Custom Cache Key Actions - Jaxelr/Nancy.RapidCache GitHub Wiki
Enable custom keys for custom actions
For certain scenarios, the flexibility of taking custom actions on the cache is allowed, these must be enable from the definition
Enable Disabled cache requests
In order to disable RapidCache on specific requests, you can add a clause on the bootstrapping definition
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);
this.EnableRapidCache(container.Resolve<IRouteResolver>(),
ApplicationPipelines);
//Enable the ability to disable the cache per request by adding a query string param
this.EnableCacheDisableKey();
}
}
}
By default the query string param to be used is http://yoururl?rapidcachedisabled=true but the key value can be customized on the definition by passing a string argument for the key
this.EnableCacheDisableKey("DisableMe");
This would transform the disable key per request to http://yoururl?disableme=true
Enable Removal from the cache by requests
To allow removing values from the cache per request we use the following defintion
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);
this.EnableRapidCache(container.Resolve<IRouteResolver>(),
ApplicationPipelines);
//Enable the ability to remove keys from the cache per request by adding a query string param
this.EnableCacheRemovalKey();
}
}
}
This will result in the removal of the cache value by the key provided on the custom key generator (usually by the url). The default query string to use would be http://yoururl?rapidcacheremove=true by we can also redefine a custom key by using the following definition
this.EnableCacheRemovalKey("RemoveMe");
This would transform the disable key per request to http://yoururl?removeme=true
NOTE: The definition of the query string is the mechanism a