Commit 89e257ae authored by Romain Loth's avatar Romain Loth

[FEAT] add a clean_cache() method for the cache obj

parent 4b74836b
...@@ -46,6 +46,9 @@ class ModelCache(dict): ...@@ -46,6 +46,9 @@ class ModelCache(dict):
class Cache: class Cache:
def __getattr__(self, key): def __getattr__(self, key):
'''
lazy init of new modelcaches: self.Node, self.User...
'''
try: try:
model = getattr(models, key) model = getattr(models, key)
except AttributeError: except AttributeError:
...@@ -54,4 +57,15 @@ class Cache: ...@@ -54,4 +57,15 @@ class Cache:
setattr(self, key, modelcache) setattr(self, key, modelcache)
return modelcache return modelcache
def clean_all(self):
'''
re-init any existing modelcaches
'''
for modelname in self.__dict__:
old_modelcache = getattr(cache, modelname)
new_modelcache = ModelCache(old_modelcache._model)
del old_modelcache
setattr(cache, modelname, new_modelcache)
cache = Cache() cache = Cache()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment