Custom Keys - Jaxelr/Nancy.RapidCache GitHub Wiki

By default the Default Cache Generator allows you to key by certain options of the request(See this link), but if those weren't necessary as granular as required for your requests, Rapid.Cache allows you to extend to your needs the interface of key generator with a very simplistic interface:

public interface ICacheKeyGenerator
{
        string Get(Request request);
}

Here is a sample usage:

    public class MyCustomGenerator : ICacheKeyGenerator
    {
        public string Get(Request request)
        {
            if (request.Headers is RequestHeaders header)
            {
                if (header.Any(x => x.Key == "Cacheable"))
                {
                    return request.Url;
                }
            }
            return null;
        }
    }

This key would allow to cache only requests that contain the header "Cacheable". The flexibility of Nancy allows us to get creative with the caching definition as needed.