When using cache_region decorator, beaker will use the following snippet to determine if it should instantiate a new cache for each function that was decorated with it.
When cache[0] is None, the decorator generates the missing cache if the corresponding region was defined with enabled = true and stores it in that local list.
I have a situation where I'm running unit tests on an application where I want to evaluate different combinations of cache regions with enabled/disable states. The problem with that local list storing the enabled cache is that if one test case later that must have it disabled, the if not cache[0]: check completely bypasses whichever new settings I set via cache_regions, since the cache is already created.
Also, since the Cache reference is stored in that local list (rather than global/package one), I cannot even wipe it.
Calling cache_managers.clear(), which has the same reference to that local cache added from the following lines will NOT clear cache[0].
When using
cache_region
decorator, beaker will use the following snippet to determine if it should instantiate a new cache for each function that was decorated with it.https://github.com/bbangert/beaker/blob/889d3055a4ca31b55a0b0681b00f2973b3250d88/beaker/cache.py#L545-L570
When
cache[0]
isNone
, the decorator generates the missing cache if the corresponding region was defined withenabled = true
and stores it in that local list.I have a situation where I'm running unit tests on an application where I want to evaluate different combinations of cache regions with enabled/disable states. The problem with that local list storing the enabled cache is that if one test case later that must have it disabled, the
if not cache[0]:
check completely bypasses whichever new settings I set viacache_regions
, since the cache is already created.Also, since the
Cache
reference is stored in that local list (rather than global/package one), I cannot even wipe it.Calling
cache_managers.clear()
, which has the same reference to that local cache added from the following lines will NOT clearcache[0]
.https://github.com/bbangert/beaker/blob/889d3055a4ca31b55a0b0681b00f2973b3250d88/beaker/cache.py#L308-L314
Is there a way to avoid this? I struggle trying to monkey-patch the cache object in
cache[0]
for my test cases.