I am looking for a way to disable and reenable caching at runtime. I want a “switch” (set of radio buttons) in my application admin area where I can turn off caching for the whole application.
I tried using cachebox.replaceCache(“mycache”, a_blackhole_cache") but then I get errors when my code hits the lookup() method.
Any ideas? My main cache uses the CFProvider provider.
Ok I got that figured out, I need to pass in the actual cache instead of just the cache name in the 2nd argument. So this works:
<cfset a_blackhole_cache = application.cacheBox.getCache(" a_blackhole_cache ") />
<cfset application.cacheBox.replaceCache(“mycache”, a_blackhole_cache) />
But now I’m getting errors where my code accesses mycache.getCachedObjectMetaData(cacheKey).createdTime
It seems the data returned by getCachedObjectMetaData() is different for different providers? Maybe I am going about this all the wrong way…
You could try setting an Application variable to control which cache namespace you are saving to.
Then, create two caches. There is an actual “BlackHole” cache that comes with ColdBox which you could use.
So, you update your “application.activeCache” variable (or whatever you call it) with the name of your desired cache, then, your production code can look something like