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
When calling clear on an instance of a SimpleMemoryCache with a namespace assigned, it will clear the entire underlying cache instead of using the instance namespace. An example:
importaiocacheimportasyncio# Define namespace constantsNS_ONE='ns.one'NS_TWO='ns.two'# Define cache referencescache_one=aiocache.SimpleMemoryCache(namespace=NS_ONE)
cache_two=aiocache.SimpleMemoryCache(namespace=NS_TWO)
asyncdefdo_something():
# Add some data to CACHE_ONE, then get it and print it out# to verify it is there.awaitcache_one.set('foo', 'bar')
val=awaitcache_one.get('foo')
print(f'cache_one k=foo v={val}')
print(f'underlying cache: {cache_one._cache}')
print('')
# Call `clear` on cache_two. Since the cache reference is differentiated# by namespace, one would expect the clear to apply to the namespace of# the referenced cache.awaitcache_two.clear()
# Get the value from cache_one again. It is not there because the# entire cache was cleared, not just the data under the cache_two namespace.val=awaitcache_one.get('foo')
print(f'cache_one k=foo v={val}')
print(f'underlying cache: {cache_one._cache}')
if__name__=='__main__':
loop=asyncio.get_event_loop()
loop.run_until_complete(do_something())
When calling
clear
on an instance of aSimpleMemoryCache
with a namespace assigned, it will clear the entire underlying cache instead of using the instance namespace. An example:Where the output is:
Specifying the namespace explicitly for the call to
clear
behaves as expected thoughleading to the output
I believe this is related to this bit of code:
https://github.com/argaen/aiocache/blob/f811995e0632b46a4597cc07007c26f755d2ffa3/aiocache/base.py#L417-L431
Where the namespace is only ever passed in via parameter, never checking to see if the instance's
namespace
member is set.The text was updated successfully, but these errors were encountered: