Refactors cache to use versatile identifier values with multiple salts.
This commit is contained in:
parent
8e365ea586
commit
b18bb959a5
@ -1,12 +1,13 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from cic_types.condiments import MetadataPointer
|
from cic_types.condiments import MetadataPointer
|
||||||
from redis import Redis
|
from redis import Redis
|
||||||
|
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger(__file__)
|
||||||
|
|
||||||
|
|
||||||
class Cache:
|
class Cache:
|
||||||
@ -39,7 +40,7 @@ def get_cached_data(key: str):
|
|||||||
return cache.get(name=key)
|
return cache.get(name=key)
|
||||||
|
|
||||||
|
|
||||||
def cache_data_key(identifier: bytes, salt: MetadataPointer):
|
def cache_data_key(identifier: Union[list, bytes], salt: MetadataPointer):
|
||||||
"""
|
"""
|
||||||
:param identifier:
|
:param identifier:
|
||||||
:type identifier:
|
:type identifier:
|
||||||
@ -49,6 +50,10 @@ def cache_data_key(identifier: bytes, salt: MetadataPointer):
|
|||||||
:rtype:
|
:rtype:
|
||||||
"""
|
"""
|
||||||
hash_object = hashlib.new("sha256")
|
hash_object = hashlib.new("sha256")
|
||||||
|
if isinstance(identifier, list):
|
||||||
|
for identity in identifier:
|
||||||
|
hash_object.update(identity)
|
||||||
|
else:
|
||||||
hash_object.update(identifier)
|
hash_object.update(identifier)
|
||||||
hash_object.update(salt.value.encode(encoding="utf-8"))
|
hash_object.update(salt.value.encode(encoding="utf-8"))
|
||||||
return hash_object.digest().hex()
|
return hash_object.digest().hex()
|
||||||
|
Loading…
Reference in New Issue
Block a user