Interface ICacheProvider
- All Known Implementing Classes:
AbstractCacheProvider,BoxCacheProvider
public interface ICacheProvider
A BoxLang cache provider that can talk to any cache implementation.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanClears an object from the cache providerClears multiple objects from the cache providervoidclearAll()Clear all the elements in the cache providerbooleanclearAll(ICacheKeyFilter filter) Clear all the elements in the cache provider with a $ICacheKeyFilterpredicate.booleanclearQuiet(String key) Clears an object from the cache provider with no stats updated or listenersClear statsconfigure(CacheService cacheService, CacheConfig config) Configure the cache provider for operationGet an object from the store with metadata trackingGet multiple objects from the store with metadata trackingget(ICacheKeyFilter filter) Get multiple objects from the store with metadata tracking using a filterGet an object from the store with metadata tracking async.Get a cache objects metadata about its performance.getCachedObjectMetadata(String... key) Get a cache objects metadata about its performance.Get the cache service that is managing this cache providerGet the cache configuration for this providerGet the interceptor pool for this cachegetKeys()Get all the keys in the cache providergetKeys(ICacheKeyFilter filter) Get all the keys in the cache provider using a filterGet all the keys in the cache provider as a streamgetKeysStream(ICacheKeyFilter filter) Get all the keys in the cache provider as a streamgetName()Get the name of the cache providerGet the object store if the cache provider supports itTries to get an object from the cache, if not found, it will call the lambda to get the value and store it in the cache with the default timeout and last access timeoutTries to get an object from the cache, if not found, it will call the lambda to get the value and store it in the cache with the default timeout and last access timeoutTries to get an object from the cache, if not found, it will call the lambda to get the value and store it in the cache with the default timeout and last access timeoutgetOrSet(String key, Supplier<Object> provider, Object timeout, Object lastAccessTimeout, IStruct metadata) Tries to get an object from the cache, if not found, it will call the lambda to get the value and store it in the cache with the default timeout and last access timeoutGet an object from cache with no metadata trackingintgetSize()Get the size of the cache providergetStats()Get the stats objectGet a key lookup structure where cachebox can build the report on.Get a structure of all the keys in the cache with their appropriate metadata structures.getStoreMetadataReport(int limit) Get a structure of all the keys in the cache with their appropriate metadata structures.getType()Get the cache provider typebooleanReturns a flag if the cache provider is enabledbooleanReturns a flag indicating if the cache has reporting enabledbooleanCheck if an object is in the storeCheck if multiple objects are in the storelookup(ICacheKeyFilter filter) Check if multiple objects are in the store using a filterbooleanlookupQuiet(String key) Check if an object is in the store with no stats updated or listenersvoidreap()Reap the cache provider of any stale or expired objectsvoidSets an object in the storage using the default timeout and last access timeoutvoidSets an object in the storage with a default last access timeoutvoidSets an object in the storagevoidSets an object in the storagevoidSet's multiple objects in the storage using all the same default timeout and last access timeoutsvoidSet's multiple objects in the storage using all the same default timeout and last access timeoutsSet the name of the cache providervoidsetQuiet(Key key, ICacheEntry value) Sets an object in the storage with no stats updated or listeners This is considered a passthrough method to the underlying storage.voidshutdown()Shutdown the cache provider
-
Method Details
-
getCacheService
CacheService getCacheService()Get the cache service that is managing this cache provider- Returns:
- The cache service
-
getStats
ICacheStats getStats()Get the stats object -
clearStats
ICacheProvider clearStats()Clear stats- Returns:
- The cache provider
-
getName
Key getName()Get the name of the cache provider -
setName
Set the name of the cache provider- Parameters:
name- The name of the cache provider
-
getType
String getType()Get the cache provider type -
getConfig
CacheConfig getConfig()Get the cache configuration for this provider -
isEnabled
boolean isEnabled()Returns a flag if the cache provider is enabled -
isReportingEnabled
boolean isReportingEnabled()Returns a flag indicating if the cache has reporting enabled -
configure
Configure the cache provider for operation- Parameters:
cacheService- The cache service that is configuring the cache providerconfig- The configuration object- Returns:
- The cache provider
-
shutdown
void shutdown()Shutdown the cache provider -
getInterceptorPool
InterceptorPool getInterceptorPool()Get the interceptor pool for this cache -
getObjectStore
IObjectStore getObjectStore()Get the object store if the cache provider supports it -
getStoreMetadataReport
Get a structure of all the keys in the cache with their appropriate metadata structures. This is used to build the reporting.[keyX->[metadataStructure]]- Parameters:
limit- The limit of keys to return, default is all keys or 0
-
getStoreMetadataReport
IStruct getStoreMetadataReport()Get a structure of all the keys in the cache with their appropriate metadata structures. This is used to build the reporting.[keyX->[metadataStructure]] This should be using a limit of 0, or all keys -
getStoreMetadataKeyMap
IStruct getStoreMetadataKeyMap()Get a key lookup structure where cachebox can build the report on. Ex: [timeout=timeout, lastAccessTimeout=idleTimeout]. It is a way for the visualizer to construct the columns correctly on the reports -
getCachedObjectMetadata
Get a cache objects metadata about its performance. This value is a structure of name-value pairs of metadata.- Parameters:
key- The key of the object- Returns:
- The metadata structure
-
getCachedObjectMetadata
Get a cache objects metadata about its performance. This value is a structure of name-value pairs of metadata.- Parameters:
key- A varargs of keys of the object- Returns:
- The metadata structure of structures
-
reap
void reap()Reap the cache provider of any stale or expired objects -
getSize
int getSize()Get the size of the cache provider -
clearAll
void clearAll()Clear all the elements in the cache provider -
clearAll
Clear all the elements in the cache provider with a $ICacheKeyFilterpredicate. This can be a lambda or method reference since it's a functional interface.- Parameters:
filter- The filter that determines which keys to clear
-
clearQuiet
Clears an object from the cache provider with no stats updated or listeners- Parameters:
key- The object key to clear- Returns:
- True if the object was cleared, false otherwise (if the object was not found in the store)
-
clear
Clears an object from the cache provider- Parameters:
key- The object key to clear- Returns:
- True if the object was cleared, false otherwise (if the object was not found in the store)
-
clear
Clears multiple objects from the cache provider- Parameters:
keys- The keys to clear- Returns:
- A struct of keys and their clear status
-
getKeys
Array getKeys()Get all the keys in the cache provider- Returns:
- An array of keys in the cache
-
getKeys
Get all the keys in the cache provider using a filter- Parameters:
filter- The filter that determines which keys to return- Returns:
- An array of keys in the cache
-
getKeysStream
Get all the keys in the cache provider as a stream- Returns:
- A stream of keys in the cache
-
getKeysStream
Get all the keys in the cache provider as a stream- Parameters:
filter- The filter that determines which keys to return- Returns:
- A stream of keys in the cache
-
lookup
Check if an object is in the store- Parameters:
key- The key to lookup in the store- Returns:
- True if the object is in the store, false otherwise
-
lookupQuiet
Check if an object is in the store with no stats updated or listeners- Parameters:
key- The key to lookup in the store- Returns:
- True if the object is in the store, false otherwise
-
lookup
Check if multiple objects are in the store- Parameters:
keys- A varargs of keys to lookup in the store- Returns:
- A struct of keys and their lookup status
-
lookup
Check if multiple objects are in the store using a filter- Parameters:
filter- The filter that determines which keys to return- Returns:
- A struct of keys and their lookup status
-
get
Get an object from the store with metadata tracking- Parameters:
key- The key to retrieve- Returns:
- The value retrieved or null
-
getAsync
Get an object from the store with metadata tracking async.- Parameters:
key- The key to retrieve- Returns:
- CompletableFuture of the value retrieved or null
-
get
Get multiple objects from the store with metadata tracking- Parameters:
keys- The keys to retrieve- Returns:
- A struct of keys and their cache entries
-
get
Get multiple objects from the store with metadata tracking using a filter- Parameters:
filter- The filter that determines which keys to return- Returns:
- A struct of keys and their cache entries
-
getQuiet
Get an object from cache with no metadata tracking- Parameters:
key- The key to retrieve- Returns:
- The cache entry retrieved or null
-
setQuiet
Sets an object in the storage with no stats updated or listeners This is considered a passthrough method to the underlying storage. Note: This mostly makes sense for the BoxCacheProvider.- Parameters:
key- The key to storevalue- The value to store
-
set
Sets an object in the storage -
set
Sets an object in the storage -
set
Sets an object in the storage with a default last access timeout- Parameters:
key- The key to storevalue- The value to storetimeout- The timeout in seconds or aDurationobject
-
set
Sets an object in the storage using the default timeout and last access timeout- Parameters:
key- The key to storevalue- The value to store
-
set
Set's multiple objects in the storage using all the same default timeout and last access timeouts- Parameters:
entries- The keys and cache entries to store
-
set
Set's multiple objects in the storage using all the same default timeout and last access timeouts -
getOrSet
Object getOrSet(String key, Supplier<Object> provider, Object timeout, Object lastAccessTimeout, IStruct metadata) Tries to get an object from the cache, if not found, it will call the lambda to get the value and store it in the cache with the default timeout and last access timeoutThis is a convenience method to avoid the double lookup pattern
var value = cache.getOrSet( "myKey", () -> { return "myValue"; });This is the same as:
var value = cache.get( "myKey" ).orElseGet( () -> { var value = "myValue"; cache.set( "myKey", value ); return value; });This method is thread safe and will only call the lambda once if the key is not found in the cache
-
getOrSet
Tries to get an object from the cache, if not found, it will call the lambda to get the value and store it in the cache with the default timeout and last access timeout -
getOrSet
Tries to get an object from the cache, if not found, it will call the lambda to get the value and store it in the cache with the default timeout and last access timeout- Parameters:
key- The key to retrieveprovider- The lambda to call if the key is not foundtimeout- The timeout in seconds or aDurationobject- Returns:
- The object
-
getOrSet
Tries to get an object from the cache, if not found, it will call the lambda to get the value and store it in the cache with the default timeout and last access timeout- Parameters:
key- The key to retrieveprovider- The lambda to call if the key is not found- Returns:
- The object
-