correct cache keys

This commit is contained in:
Emmanuel Viennet 2021-07-20 07:52:42 +03:00
parent 5b2d4e47ec
commit 783a8a5188

View File

@ -75,7 +75,7 @@ class ScoDocCache:
@classmethod @classmethod
def _get_key(cls, oid): def _get_key(cls, oid):
return cls.prefix + g.scodoc_dept + oid return g.scodoc_dept + "_" + cls.prefix + oid
@classmethod @classmethod
def get(cls, oid): def get(cls, oid):
@ -87,6 +87,14 @@ class ScoDocCache:
"""Store evaluation""" """Store evaluation"""
return CACHE.set(cls._get_key(oid), value, timeout=cls.timeout) return CACHE.set(cls._get_key(oid), value, timeout=cls.timeout)
@classmethod
def get_cached(cls, oid):
"""get cached object. Clients should use .get()
This function is usefull for tests, because get() may be
overloaded by subclasses.
"""
return ScoDocCache.get(oid)
@classmethod @classmethod
def delete(cls, oid): def delete(cls, oid):
"""Remove from cache""" """Remove from cache"""
@ -134,8 +142,11 @@ class AbsSemEtudCache(ScoDocCache):
C'est pourquoi il expire après timeout secondes. C'est pourquoi il expire après timeout secondes.
Le timeout evite aussi d'éliminer explicitement ces éléments cachés lors Le timeout evite aussi d'éliminer explicitement ces éléments cachés lors
des suppressions d'étudiants ou de semestres. des suppressions d'étudiants ou de semestres.
Clé: etudid + "_" + date_debut + "_" + date_fin
Valeur: (nb_abs, nb_abs_just)
""" """
prefix = "ABSE"
timeout = 60 * 60 # ttl 60 minutes timeout = 60 * 60 # ttl 60 minutes