How can you refresh all regions in Beaker cache in Pyramid?
Asked Answered
A

2

10

I am trying to setup caching on a web server I have built using Pyramid. I am using pyramid_beaker, which creates a back-end to use Beaker for caching.

I have been using cached region decorators to implement the caching.

A sample cached region looks like this:

def getThis(request):
    def invalidate_data(getData,'long_term',search_term):
         region_invalidate(getData,'long_term',search_term)
    @cached_region('long_term')
    def getData(search_term):
         return response
    try:
         request.matchdict['refresh']
    except:
         pass
    search_term = request.matchdict['searchterm']
    return getData(search_term)

Now that the caching works fine and I can trigger cache refresh on each region, I was wondering how I might refresh ALL regions?

Aframe answered 25/6, 2012 at 10:31 Comment(0)
A
4

Beaker has a dict object of all CacheManagers that can be used to iterate over to clear each:

from beaker.cache import cache_managers
for _cache in cache_managers.values():
    _cache.clear()  
Aframe answered 10/1, 2013 at 4:56 Comment(0)
A
0

If you were saving to file, you could probably just erase the folder containing all caches. This is probably not the best solution but it should be pretty fast and effective.

Amanita answered 27/6, 2012 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.