-
Notifications
You must be signed in to change notification settings - Fork 48
Description
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?