On Apr 9, 2012, at 3:33 PM, Michael Bayer wrote:
>
> assuming you're talking about beaker's middleware, all it did was stick a
> CacheManager object in the wsgi environ. You can certainly do that with
> dogpile cache regions too.
>
> After considering some approaches I think you could just subclass CacheRegion
> and overrride "backend" and "configure" to pull from the wsgi environment,
> some system of making it available would need to be devised (pylons made this
> easy with the thread local registries but I understand we don't do that with
> Pyramid....)
Here's what that could look like:
class ConfigInjectedRegion(CacheRegion):
"""A :class:`.CacheRegion` which accepts a runtime method
of determining backend configuration.
Supports ad-hoc backends per call, allowing storage of
backend implementations inside of application specific
registries, such as wsgi environments.
"""
def region_registry(self):
"""Return a dictionary where :class:`.ConfigInjectedRegion`
will store backend implementations.
This is typically stored in a place like wsgi
environment or other application configuration.
"""
raise NotImplementedError()
def configure(self, backend, **kw):
self.region_registry()[self.name] = super(
ConfigInjectedRegion, self).configure(backend, **kw)
@property
def backend(self):
return self.region_registry()[self.name]
Suppose we were using Pylons' config stacked proxy. Usage is then like:
from pylons import config
class MyRegions(ConfigInjectedRegion):
def region_registry(self):
return config['dogpile_registries']
def setup_my_app(config):
config['dogpile_registries'] = {}
I haven't used Pyramid much yet but whatever system it has of "set up these
config/request things for the lifespan of this request", you'd inject onto the
"MyRegions" object.
I could commit ConfigInjectedRegion as it is, but I'd want to check that this
use case works out.
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.