How invalidate beaker_cache in Pylons?
Need to invalidate a cache created by beaker_cache
decorator for a specific controller action:
from pylons.decorators.cache import beaker_cache
class SampleControlle开发者_如何学运维r(BaseController):
@beaker_cache()
def home(self):
c.data = expensive_call()
return render('/home.myt')
def __clear_home_cache(self):
pass
Can I use region_invalidate()
inside __clear_home_cache function?
One way to find out how to invalidate stuff cached by beaker_cache
decorator is to look at how it works and what it does. It is defined in pylons.decorators.cache
module, here's the corresponding source file on GitHub.
Basically you're looking for the logic that chooses namespace and cache key for a given controller action. This is done by create_cache_key() function in that file. And, incidentally, that function has a helpful comment:
Example:
from pylons import cache
from pylons.decorators.cache import create_cache_key
namespace, key = create_cache_key(MyController.some_method)
cache.get_cache(namespace).remove(key)
精彩评论