Caching APIs
MemoryZoneReadThroughCache
The MemoryZoneReadThroughCache
class provides an in-memory caching solution
with automatic read-through capabilities. This cache stores data in memory for
fast access and automatically handles cache misses.
Constructor
ts
Creates a new instance of the memory cache with read-through capabilities.
name
- A unique identifier for the cache instancecontext
- The ZuploContext objectT
- The type of data stored in the cache (defaults tounknown
)
Methods
get
Retrieves a value from the cache by its key. Returns undefined
if not found.
ts
put
Stores a value in the cache with a time-to-live (TTL) in seconds.
ts
delete
Removes a value from the cache.
ts
Example
ts
Best Practices
- Use descriptive cache names to avoid collisions between different cache instances
- Set appropriate TTL values based on your data freshness requirements
- Consider memory usage when caching large objects
- The cache is scoped to the current worker instance and not shared across instances
See Also
- ZoneCache - For distributed caching across zones
- StreamingZoneCache - For caching streaming data
- BackgroundLoader - For automatic cache population