No factory is needed. Here is my recipe:
from beaker.util import parse_cache_config_options
import beaker.cache
settings=config.registry.settings
cfg=parse_cache_config_options(settings)
beaker.cache.cache_regions.update(cfg["cache_regions"])
after putting that in your startup code in run.py you can use the beaker
cache_regions decorator for normal caching.
Wichert.
--
Wichert Akkerman <wic...@wiggy.net> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.
I tried my idea anyway, even if it didn't seem the correct way to do
it (I learned something at least), and it works:
# pyramid_beaker_cache/__init__.py
from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options
from pyramid.request import Request
def BeakerCacheRequestFactory(**options):
class BeakerCacheRequest(Request):
_cache_options = options
_cache = None
@property
def cache(self):
if self._cache is None:
self._cache = CacheManager(**self._cache_options)
return self._cache
return BeakerCacheRequest
def request_factory_from_settings(settings):
""" Return a Pyramid request using Beaker cache settings
supplied from a Paste configuration file"""
options = parse_cache_config_options(settings)
return BeakerCacheRequestFactory(**options)
# application/__init__.py
# [...]
config = Configurator(settings=settings)
request_factory = request_factory_from_settings(settings)
config.set_request_factory(request_factory)
# [...]
And then I use the cache.region decorator:
@self.request.cache.region('short_term', 'something')
It works, but I will try your method next.
Thanks.
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-devel" group.
> To post to this group, send email to pylons...@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-devel...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-devel?hl=en.
>
>