@@ -4,7 +4,7 @@ This section contains documentation for experimental Zarr Python features. The f
44
55## ` CacheStore `
66
7- Zarr Python 3.1.4 adds ` zarr.experimental.cache_store.CacheStore ` provides a dual-store caching implementation
7+ Zarr Python 3.1.4 adds [ ` zarr.experimental.cache_store.CacheStore ` ] [ ] provides a dual-store caching implementation
88that can be wrapped around any Zarr store to improve performance for repeated data access.
99This is particularly useful when working with remote stores (e.g., S3, HTTP) where network
1010latency can significantly impact data access speed.
@@ -24,7 +24,7 @@ Because the `CacheStore` uses an ordinary Zarr `Store` object as the caching lay
2424Creating a CacheStore requires both a source store and a cache store. The cache store
2525can be any Store implementation, providing flexibility in cache persistence:
2626
27- ``` python exec="true" session="experimental" source="above" result="ansi"
27+ ``` python exec="true" session="experimental" source="above"
2828import zarr
2929from zarr.storage import LocalStore
3030import numpy as np
@@ -73,6 +73,7 @@ elapsed_nocache = time.time() - start
7373
7474# Cache provides speedup for repeated access
7575speedup = elapsed_nocache / elapsed_cache
76+ print (f " Speedup is { speedup} " )
7677```
7778
7879Cache effectiveness is particularly pronounced with repeated access to the same data chunks.
@@ -84,7 +85,7 @@ The CacheStore can be configured with several parameters:
8485
8586** max_size** : Controls the maximum size of cached data in bytes
8687
87- ``` python exec="true" session="experimental" source="above" result="ansi"
88+ ``` python exec="true" session="experimental" source="above"
8889# 256MB cache with size limit
8990cache = CacheStore(
9091 store = source_store,
@@ -102,7 +103,7 @@ cache = CacheStore(
102103
103104** max_age_seconds** : Controls time-based cache expiration
104105
105- ``` python exec="true" session="experimental" source="above" result="ansi"
106+ ``` python exec="true" session="experimental" source="above"
106107# Cache expires after 1 hour
107108cache = CacheStore(
108109 store = source_store,
@@ -162,7 +163,7 @@ The `cache_info()` method returns a dictionary with detailed information about t
162163
163164The CacheStore provides methods for manual cache management:
164165
165- ``` python exec="true" session="experimental" source="above" result="ansi"
166+ ``` python exec="true" session="experimental" source="above"
166167# Clear all cached data and tracking information
167168import asyncio
168169asyncio.run(cached_store.clear_cache())
@@ -192,7 +193,7 @@ and use any store type for the cache backend:
192193
193194### Local Store with Memory Cache
194195
195- ``` python exec="true" session="experimental-memory-cache" source="above" result="ansi"
196+ ``` python exec="true" session="experimental-memory-cache" source="above"
196197from zarr.storage import LocalStore, MemoryStore
197198from zarr.experimental.cache_store import CacheStore
198199from tempfile import mkdtemp
@@ -209,7 +210,7 @@ cached_store = CacheStore(
209210
210211### Memory Store with Persistent Cache
211212
212- ``` python exec="true" session="experimental-local-cache" source="above" result="ansi"
213+ ``` python exec="true" session="experimental-local-cache" source="above"
213214from tempfile import mkdtemp
214215from zarr.storage import MemoryStore, LocalStore
215216from zarr.experimental.cache_store import CacheStore
@@ -255,10 +256,12 @@ zarr_array[:] = np.random.random((100, 100))
255256start = time.time()
256257data = zarr_array[20 :30 , 20 :30 ] # First access (cache miss)
257258first_access = time.time() - start
259+ print (f " First access took { first_access} " )
258260
259261start = time.time()
260262data = zarr_array[20 :30 , 20 :30 ] # Second access (cache hit)
261263second_access = time.time() - start
264+ print (f " Second access took { second_access} " )
262265
263266# Check cache statistics
264267info = cached_store.cache_info()
0 commit comments