python - How do I use beaker caching in Pyramid? -
i have following in ini file:
cache.regions = default_term, second, short_term, long_term cache.type = memory cache.second.expire = 1 cache.short_term.expire = 60 cache.default_term.expire = 300 cache.long_term.expire = 3600 and in __init__.py:
from pyramid_beaker import set_cache_regions_from_settings set_cache_regions_from_settings(settings) however, i'm not sure how perform actual caching in views/handlers. there decorator available? figured there in response api cache_control available - instructs user cache data. not cache server-side.
any ideas?
my mistake call decorator function @cache_region on view-callable. got no error reports there no actual caching. so, in views.py trying like:
@cache_region('long_term') def photos_view(request): #just example of costly call google picasa gd_client = gdata.photos.service.photosservice() photos = gd_client.getfeed('...') return { 'photos': photos.entry } no errors , no caching. view-callable start require parameter! works:
#make separate function , cache @cache_region('long_term') def get_photos(): gd_client = gdata.photos.service.photosservice() photos = gd_client.getfeed('...') return photos.entry and in view-callable just:
def photos_view(request): return { 'photos': get_photos() } the same way works @cache.cache etc.
summary: do not try cache view-callables.
ps. still have slight suspiction view callables can cached :)
upd.: hlv later explains, when cache view-callabe, cache never hit, because @cache_region uses callable's request param cache id. , request unique every request.
Comments
Post a Comment