From 1e4c7cd5cde09a5c58bc601cae3f5a49eb615399 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Tue, 18 Jun 2024 01:03:19 +0200
Subject: [PATCH] On cache emptying, also ._disappear() any objects held in it.

---
 plomtask/db.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

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
-- 
2.30.2