Merge pull request #4912 from FinnStutzenstein/ResetCacheException

Added missing ResetCache-handling
This commit is contained in:
Finn Stutzenstein 2019-08-14 12:00:05 +02:00 committed by GitHub
commit ba5782a655
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -309,12 +309,9 @@ class RedisCacheProvider:
""" """
Returns one element from the cache. Returns None, when the element does not exist. Returns one element from the cache. Returns None, when the element does not exist.
""" """
try: return await self.eval(
return await self.eval( "get_element_data", [self.get_full_data_cache_key()], [element_id]
"get_element_data", [self.get_full_data_cache_key()], [element_id] )
)
except aioredis.errors.ReplyError:
raise CacheReset()
@ensure_cache_wrapper() @ensure_cache_wrapper()
async def add_changed_elements( async def add_changed_elements(
@ -457,6 +454,8 @@ class RedisCacheProvider:
send. send.
If the script uses the ensure_cache-prefix, the first key must be the full_data If the script uses the ensure_cache-prefix, the first key must be the full_data
cache key. This is checked here. cache key. This is checked here.
Also this method incudes the custom "CacheReset" error, which will be raised in
python, if the lua-script returns a "cache_reset" string as an error response.
""" """
hash = self._script_hashes[script_name] hash = self._script_hashes[script_name]
if ( if (
@ -472,10 +471,24 @@ class RedisCacheProvider:
return await redis.evalsha(hash, keys, args) return await redis.evalsha(hash, keys, args)
except aioredis.errors.ReplyError as e: except aioredis.errors.ReplyError as e:
if str(e).startswith("NOSCRIPT"): if str(e).startswith("NOSCRIPT"):
return await redis.eval(self.scripts[script_name][0], keys, args) return await self._eval(redis, script_name, keys=keys, args=args)
elif str(e) == "cache_reset":
raise CacheReset()
else: else:
raise e raise e
async def _eval(
self, redis: Any, script_name: str, keys: List[str] = [], args: List[Any] = []
) -> Any:
""" Do a real eval of the script (no hash used here). Catches "cache_reset". """
try:
return await redis.eval(self.scripts[script_name][0], keys, args)
except aioredis.errors.ReplyError as e:
if str(e) == "cache_reset":
raise CacheReset()
else:
raise e
class MemmoryCacheProvider: class MemmoryCacheProvider:
""" """