Skip to content

Commit c589b27

Browse files
committed
Add targeted sidecar cache invalidation when persistent sidecars are replaced
1 parent 5ae15cb commit c589b27

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/blosc2/indexing.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,15 @@ def _sidecar_storage_category(category: str) -> str:
854854
return category.removesuffix("_handle")
855855

856856

857+
def _invalidate_sidecar_cache_entries(array: blosc2.NDArray, token: str, category: str, name: str) -> None:
858+
"""Drop cached data/handles for a sidecar before replacing its storage."""
859+
storage_category = _sidecar_storage_category(category)
860+
categories = {storage_category, f"{storage_category}_handle"}
861+
for cache_category in categories:
862+
_DATA_CACHE.pop(_data_cache_key(array, token, cache_category, name), None)
863+
_SIDECAR_HANDLE_CACHE.pop(_sidecar_handle_cache_key(array, token, cache_category, name), None)
864+
865+
857866
def _open_sidecar_handle(array: blosc2.NDArray, token: str, category: str, name: str, path: str | None):
858867
cache_key = _sidecar_handle_cache_key(array, token, category, name)
859868
cached = _SIDECAR_HANDLE_CACHE.get(cache_key)
@@ -1032,6 +1041,7 @@ def _store_array_sidecar(
10321041
) -> dict:
10331042
cache_key = _data_cache_key(array, token, category, name)
10341043
handle_cache_key = _sidecar_handle_cache_key(array, token, category, name)
1044+
_invalidate_sidecar_cache_entries(array, token, category, name)
10351045
if persistent:
10361046
path = _sidecar_path(array, token, kind, f"{category}.{name}")
10371047
blosc2.remove_urlpath(path)
@@ -1074,6 +1084,7 @@ def _create_persistent_sidecar_handle(
10741084
blocks: tuple[int, ...] | None = None,
10751085
cparams: dict | None = None,
10761086
) -> tuple[blosc2.NDArray | None, dict]:
1087+
_invalidate_sidecar_cache_entries(array, token, category, name)
10771088
path = _sidecar_path(array, token, kind, f"{category}.{name}")
10781089
blosc2.remove_urlpath(path)
10791090
kwargs = {"urlpath": path, "mode": "w"}

0 commit comments

Comments
 (0)