From: Christian Heller Date: Mon, 17 Jun 2024 23:03:19 +0000 (+0200) Subject: On cache emptying, also ._disappear() any objects held in it. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/todos?a=commitdiff_plain;h=1e4c7cd5cde09a5c58bc601cae3f5a49eb615399;p=plomtask On cache emptying, also ._disappear() any objects held in it. --- diff --git a/plomtask/db.py b/plomtask/db.py index 3917ce0..385e798 100644 --- a/plomtask/db.py +++ b/plomtask/db.py @@ -315,7 +315,13 @@ class BaseModel(Generic[BaseModelId]): @classmethod def empty_cache(cls) -> None: - """Empty class's cache.""" + """Empty class's cache, and disappear all former inhabitants.""" + # pylint: disable=protected-access + # (cause we remain within the class) + if hasattr(cls, 'cache_'): + to_disappear = list(cls.cache_.values()) + for item in to_disappear: + item._disappear() cls.cache_ = {} @classmethod