Interface ICacheProvider

All Known Implementing Classes:
AbstractCacheProvider, BoxCacheProvider

public interface ICacheProvider
A BoxLang cache provider that can talk to any cache implementation.
  • 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

      ICacheProvider setName(Key name)
      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

      ICacheProvider configure(CacheService cacheService, CacheConfig config)
      Configure the cache provider for operation
      Parameters:
      cacheService - The cache service that is configuring the cache provider
      config - 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

      IStruct getStoreMetadataReport(int limit)
      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

      IStruct getCachedObjectMetadata(String key)
      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

      IStruct getCachedObjectMetadata(String... key)
      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

      boolean clearAll(ICacheKeyFilter filter)
      Clear all the elements in the cache provider with a $ICacheKeyFilter predicate. 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

      boolean clearQuiet(String key)
      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

      boolean clear(String key)
      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

      IStruct clear(String... keys)
      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

      Array getKeys(ICacheKeyFilter filter)
      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

      Stream<String> getKeysStream()
      Get all the keys in the cache provider as a stream
      Returns:
      A stream of keys in the cache
    • getKeysStream

      Stream<String> getKeysStream(ICacheKeyFilter filter)
      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

      boolean lookup(String key)
      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

      boolean lookupQuiet(String key)
      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

      IStruct lookup(String... keys)
      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

      IStruct lookup(ICacheKeyFilter filter)
      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

      Attempt<Object> get(String key)
      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

      IStruct get(String... keys)
      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

      IStruct get(ICacheKeyFilter filter)
      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

      Attempt<Object> getQuiet(String key)
      Get an object from cache with no metadata tracking
      Parameters:
      key - The key to retrieve
      Returns:
      The cache entry retrieved or null
    • setQuiet

      void setQuiet(Key key, ICacheEntry value)
      Sets an object in the storage with no stats updated or listeners
      Parameters:
      key - The key to store
      value - The value to store
    • set

      void set(String key, Object value, Duration timeout, Duration lastAccessTimeout, IStruct metadata)
      Sets an object in the storage
      Parameters:
      key - The key to store
      value - The value to store
      timeout - The timeout in seconds
      lastAccessTimeout - The last access timeout in seconds
      metadata - The metadata to store
    • set

      void set(String key, Object value, Duration timeout, Duration lastAccessTimeout)
      Sets an object in the storage
      Parameters:
      key - The key to store
      value - The value to store
      timeout - The timeout in seconds
      lastAccessTimeout - The last access timeout in seconds
    • set

      void set(String key, Object value, Duration timeout)
      Sets an object in the storage with a default last access timeout
      Parameters:
      key - The key to store
      value - The value to store
      timeout - The timeout in seconds
    • set

      void set(String key, Object value)
      Sets an object in the storage using the default timeout and last access timeout
      Parameters:
      key - The key to store
      value - The value to store
    • set

      void set(IStruct entries)
      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

      void set(IStruct entries, Duration timeout, Duration lastAccessTimeout)
      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 in the cache
      timeout - The timeout in seconds
      lastAccessTimeout - The last access timeout in seconds
    • getOrSet

      Object getOrSet(String key, Supplier<Object> provider, Duration timeout, Duration 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 timeout

      This 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

      Parameters:
      key - The key to retrieve
      provider - The lambda to call if the key is not found
      timeout - The timeout in seconds
      lastAccessTimeout - The last access timeout in seconds
      metadata - The metadata to store
    • getOrSet

      Object getOrSet(String key, Supplier<Object> provider, Duration timeout, Duration lastAccessTimeout)
      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 retrieve
      provider - The lambda to call if the key is not found
      timeout - The timeout in seconds
      lastAccessTimeout - The last access timeout in seconds
      Returns:
      The object
    • getOrSet

      Object getOrSet(String key, Supplier<Object> provider, Duration timeout)
      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 retrieve
      provider - The lambda to call if the key is not found
      timeout - The timeout in seconds
      Returns:
      The object
    • getOrSet

      Object getOrSet(String key, Supplier<Object> provider)
      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 retrieve
      provider - The lambda to call if the key is not found
      Returns:
      The object