Disable / prevent memoize using plone.memoize.ram

I have a Zope utility and a method that executes network processes. Since the result has been valid for a while, I use plone.memoize.ram to cache the result.

 MyClass(object): @cache(cache_key) def do_auth(self, adapter, data): # performing expensive network process here 

... and cache function:

 def cache_key(method, utility, data): return time() // 60 * 60)) 

But I want memoization to be executed when the do_auth call returns empty results (or causes network errors).

Looking at the plone.memoize code, it seems to me that I need a raise ram.DontCache() exception, but before that I need to examine the original cached value.

How to get cached data from cache storage?

+6
source share
1 answer

I put this together from several codes that I wrote ... It has not been tested, but it can help you.

You can access cached data using the ICacheChooser utility. This calling method requires a dotted name for the function you cached in your case

 key = '{0}.{1}'.format(__name__, method.__name__) cache = getUtility(ICacheChooser)(key) storage = cache.ramcache._getStorage()._data cached_infos = storage.get(key) 

Cached_infos should have all the information you need.

+3
source

All Articles