You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Default behavior if the region hasn't been configured #65
Migrated issue, originally created by Shayne Miel (FragLegs)
I'm trying to set up my code so that functions decorated with @region.cache_on_arguments will simply call the decorated function if the region has not yet been configured. I am aware of the null backend, but if I set that as the default backend, I cannot later set a real backend. I suspect that I may be using the library incorrectly.
Here is what I would like to be able to do:
import dogpile.cache
region = dogpile.cache.make_region()
@region.cache_on_arguments()
def foo(x):
return x * 2
bar = foo(21)
region = region.configure('dogpile.cache.memory')
baz = foo(21)
But I get an AttributeError: 'CacheRegion' object has no attribute 'expiration_time'
If I try to use the null backend as a default configuration, like this:
import dogpile.cache
region = dogpile.cache.make_region().configure('dogpile.cache.null')
@region.cache_on_arguments()
def foo(x):
return x * 2
bar = foo(21)
region = region.configure('dogpile.cache.memory')
baz = foo(21)
I get a dogpile.cache.exception.RegionAlreadyConfigured error.
This could probably be solved by putting a check for whether the backend is configured in get_or_create(), but I'm not sure where the best place to put it would be. Am I just missing a way to achieve what I'm trying to do?
Ok tell you what, most people wouldn't want this behavior, because if their application is not correctly configuring their backend, they want to know, they don't want it to silently fail. So I want to look into allowing this as an option. Although it seems here the PR is only limited to just one of the cache decorators, not the other decorators and not any of the other caching methods.
how about this. you configure your region right up front with NullBackend, then we add a flag to configure, "replace_existing_backend=True". Then you can just reconfigure it later. Hows that?
That sounds great. The PR was only intended to explain my proposed solution - I figured it was probably not the right place to add it. I like the configuration option better. Would you like me to try to implement it and send a new pull request?
Activity
sqlalchemy-bot commentedon Jul 18, 2014
Shayne Miel (FragLegs) wrote:
If this is something you're interested in, I've created a pull request with the simple change here: https://bitbucket.org/zzzeek/dogpile.cache/pull-request/21/added-a-check-for-an-unconfigured-backend/diff
sqlalchemy-bot commentedon Jul 18, 2014
Michael Bayer (zzzeek) wrote:
Ok tell you what, most people wouldn't want this behavior, because if their application is not correctly configuring their backend, they want to know, they don't want it to silently fail. So I want to look into allowing this as an option. Although it seems here the PR is only limited to just one of the cache decorators, not the other decorators and not any of the other caching methods.
how about this. you configure your region right up front with NullBackend, then we add a flag to configure, "replace_existing_backend=True". Then you can just reconfigure it later. Hows that?
sqlalchemy-bot commentedon Jul 18, 2014
Shayne Miel (FragLegs) wrote:
That sounds great. The PR was only intended to explain my proposed solution - I figured it was probably not the right place to add it. I like the configuration option better. Would you like me to try to implement it and send a new pull request?
sqlalchemy-bot commentedon Jul 18, 2014
Michael Bayer (zzzeek) wrote:
sure send away
sqlalchemy-bot commentedon Sep 12, 2015
Michael Bayer (zzzeek) wrote:
an existing backend to be replaced.
fixes Default behavior if the region hasn't been configured #65
→ 9df5b58
sqlalchemy-bot commentedon Sep 12, 2015
Changes by Michael Bayer (zzzeek):