Support glob patterns in cache.clear
Allow clearing multiple cache entries using glob-style patterns. Import fnmatch and detect pattern characters (*, ?, [) in the area argument; if present, collect matching keys with fnmatch.fnmatch and remove them safely while holding the lock. Fallback behavior remains unchanged for exact-key clears.
frdel committed
Feb 25, 2026 at 06:30 UTC
fcdb6285cfabe116d61ff10dc69809fb835b782b
1 file changed
+7
python/helpers/cache.py
+7
@@ -1,3 +1,4 @@
1
+import fnmatch
2
import threading
3
from typing import Any
4
@@ -25,6 +26,12 @@ def remove(area: str, key: str) -> None:
26
27
def clear(area: str) -> None:
28
with _lock:
29
+ if any(ch in area for ch in "*?["):
30
+ keys_to_remove = [k for k in _cache.keys() if fnmatch.fnmatch(k, area)]
31
+ for k in keys_to_remove:
32
+ _cache.pop(k, None)
33
+ return
34
+
35
_cache.pop(area, None)
36
37