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
fromdolimportcache_thistrace= []
cache=dict()
disk=dict()
classA:
@cache_this(cache=disk)deff(self):
trace.append('In f method')
return42a=A()
asserta.f==42asserttrace== ['In f method'] # proof that the method was called assertdisk['f'] ==42# proof that the result was cached in diskasserta.f==42# access the attribute againasserttrace== ['In f method'] # proof that the method was NOT called again
It would be convenient to be able to stack caches like this (this doesn't work):
classA:
@cache_this(cache=cache)@cache_this(cache=disk)deff(self):
trace.append('In f method')
return42
so that the net effect would be to save the output of f in both disk and cache, but read from cache only (when it's there), and if disk already has an f, to read from disk (but write to cache).
What is needed is probably the ability for cache_this to see what it's wrapping, and if it's already a CachedProperty, it should wrap the wrapped method of it. Essentially, getting to this (which works):
fromdolimportcache_this, CascadedStoresfromcollectionsimportChainMaptrace= []
cache=dict()
disk=dict(g=8)
cascade_cache_this=cache_this(cache=CascadedStores([cache, disk]))
classA:
@cascade_cache_thisdeff(self):
trace.append('In f method')
return42@cascade_cache_thisdefg(self):
trace.append('In g method')
a=A()
asserta.f==42asserttrace== ['In f method'] # proof that the method was called assertcache['f'] ==42# proof that the result was cached in chached_aassertdisk['f'] ==42# proof that the result was cached in chached_basserta.f==42# access the attribute againasserttrace== ['In f method'] # proof that the f method was NOT called againasserta.g==8asserttrace== ['In f method'] # proof that the g method was NEVER called (it got the value from disk)
The text was updated successfully, but these errors were encountered:
Consider this code:
It would be convenient to be able to stack caches like this (this doesn't work):
so that the net effect would be to save the output of
f
in bothdisk
andcache
, but read fromcache
only (when it's there), and ifdisk
already has anf
, to read fromdisk
(but write tocache
).What is needed is probably the ability for cache_this to see what it's wrapping, and if it's already a
CachedProperty
, it should wrap the wrapped method of it. Essentially, getting to this (which works):The text was updated successfully, but these errors were encountered: