Skip to main content

manager: add a comment about the order of operations

ID
447f672
date
2026-11-06 22:47:53+00:00
author
Alex Chan <alexc@tailscale.com>
parent
4dff711
message
manager: add a comment about the order of operations

I inadvertently messed up the ordering here, and if you create a duplicate
storage before checking for dupes, the extra storage is never closed.
changed files
1 file, 5 additions

Changed files

src/funkycache/manager.py (10753 → 10969)

diff --git a/src/funkycache/manager.py b/src/funkycache/manager.py
index 8058a6b..ae1d0d1 100644
--- a/src/funkycache/manager.py
+++ b/src/funkycache/manager.py
@@ -140,9 +140,14 @@ class FunkyCache:
             dep_paths = _dep_paths(func, files=[Path(p) for p in (files or [])])
             dep_values = values or []
 
+            # Check if we already have a cache for this function.
+            #
+            # We must do this before creating the storage, or we could have
+            # a dangling, unclosed storage hanging around.
             func_name = _canonical_spec(func)
             if func_name in self._known_caches:
                 raise TypeError(f"Duplicate cache for {func_name}")
+
             input_sig = _input_signature(dep_paths, dep_values)
             storage = self._create_storage(
                 func_name,