Class SimpleCache<V>
java.lang.Object
com.google.genkit.core.middleware.SimpleCache<V>
- Type Parameters:
V- the value type
- All Implemented Interfaces:
MiddlewareCache<V>
SimpleCache is a thread-safe in-memory cache implementation for use with
caching middleware.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a SimpleCache with no TTL (entries never expire).SimpleCache(long ttlMs) Creates a SimpleCache with the specified TTL. -
Method Summary
-
Constructor Details
-
SimpleCache
public SimpleCache()Creates a SimpleCache with no TTL (entries never expire). -
SimpleCache
public SimpleCache(long ttlMs) Creates a SimpleCache with the specified TTL.- Parameters:
ttlMs- time-to-live in milliseconds (0 for no expiration)
-
-
Method Details
-
get
Description copied from interface:MiddlewareCacheGets a value from the cache.- Specified by:
getin interfaceMiddlewareCache<V>- Parameters:
key- the cache key- Returns:
- the cached value, or null if not found
-
put
Description copied from interface:MiddlewareCachePuts a value in the cache.- Specified by:
putin interfaceMiddlewareCache<V>- Parameters:
key- the cache keyvalue- the value to cache
-
remove
Description copied from interface:MiddlewareCacheRemoves a value from the cache.- Specified by:
removein interfaceMiddlewareCache<V>- Parameters:
key- the cache key
-
clear
public void clear()Description copied from interface:MiddlewareCacheClears all values from the cache.- Specified by:
clearin interfaceMiddlewareCache<V>
-
size
public int size()Returns the number of entries in the cache.- Returns:
- the cache size
-