Disk Cache store - Jaxelr/Nancy.RapidCache GitHub Wiki

We need to provide RapidCache with an implementation of the ICacheStore interface to use as a repository for our cache responses. By default, it uses a Concurrent Dictionary in memory, but we can redefine a custom store if necessary. In the case that we have defined a self hosted Nancy app, we can declare a Disk Cache Store, to use caching for caching our requests:

using Nancy.RapidCache.Extensions;
using Nancy.Routing;
using Nancy.TinyIoc;
using Nancy.Bootstrapper;

namespace MyCustomWebApp
{
    public class ApplicationBootrapper : DefaultNancyBootstrapper
    {
        protected override void ApplicationStartup
        (TinyIoCContainer container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            //The Disk Cache Store is declared explicitly.
            this.EnableRapidCache(
                container.Resolve<IRouteResolver>(), 
                ApplicationPipelines, 
                new[] { "query", "form", "accept" }, 
                new DiskCacheStore("c:/tmp/cache")); //path of the files.
        }
    }
}

By default, the disk cache store keeps the files for 24 minutes. But the declaration contains an overload that allows you to optionally define an expiration to delete files on disk.

using Nancy.RapidCache.Extensions;
using Nancy.Routing;
using Nancy.TinyIoc;
using Nancy.Bootstrapper;

namespace MyCustomWebApp
{
    public class ApplicationBootrapper : DefaultNancyBootstrapper
    {
        protected override void ApplicationStartup
        (TinyIoCContainer container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            //The Disk Cache Store is declared explicitly.
            this.EnableRapidCache(
                container.Resolve<IRouteResolver>(), 
                ApplicationPipelines, 
                new[] { "query", "form", "accept" }, 
                new DiskCacheStore("c:/tmp/cache", new TimeSpan(0, 0, 30, 0)));
        }
    }
}