Class AerospikeCache

java.lang.Object
org.springframework.data.aerospike.cache.AerospikeCache
All Implemented Interfaces:
Cache

public class AerospikeCache extends Object implements Cache
A Cache Cache implementation backed by Aerospike database as store. Create and configure Aerospike cache instances via AerospikeCacheManager.
Author:
Venil Noronha
  • Constructor Details

  • Method Details

    • clear

      public void clear()
      Clears the cache by truncating the configured cache's set (in the configured namespace).
      Specified by:
      clear in interface Cache
    • evict

      public void evict(Object key)
      Deletes the key from Aerospike database.
      Specified by:
      evict in interface Cache
      Parameters:
      key - The key to delete.
    • getName

      public String getName()
      Get cache's name.
      Specified by:
      getName in interface Cache
      Returns:
      The cache's name.
    • getNativeCache

      public Object getNativeCache()
      Get the underlying native cache provider - the Aerospike client.
      Specified by:
      getNativeCache in interface Cache
      Returns:
      The aerospike client.
    • get

      public <T> T get(Object key, Callable<T> valueLoader)
      Return the value (bins) from the Aerospike database to which this cache maps the specified key, obtaining that value from valueLoader if necessary. This method provides a simple substitute for the conventional "if cached, return; otherwise create, cache and return" pattern.
      Specified by:
      get in interface Cache
      Parameters:
      key - The key whose associated value is to be returned.
      valueLoader - The value loader that might contain the value (bins).
      Returns:
      The value (bins) to which this cache maps the specified key.
    • get

      public <T> T get(Object key, Class<T> type)
      Return the value (bins) from the Aerospike database to which this cache maps the specified key. Generically specifying a type that return value will be cast to.
      Specified by:
      get in interface Cache
      Parameters:
      key - The key whose associated value (bins) is to be returned.
      type - The required type of the returned value (can be null to bypass a type check; in case of a null value found in the cache, the specified type is irrelevant).
      Returns:
      The value (bins) to which this cache maps the specified key (which may be null itself), or also null if the cache contains no mapping for this key.
    • get

      public Cache.ValueWrapper get(Object key)
      Returns the value (bins) from the Aerospike database to which this cache maps the specified key. Returns null if the cache contains no mapping for this key; otherwise, the cached value (which may be null itself) will be returned in a Cache.ValueWrapper.
      Specified by:
      get in interface Cache
      Parameters:
      key - The key whose associated value (bins) is to be returned.
      Returns:
      The value (bins) to which this cache maps the specified key, contained within a Cache.ValueWrapper which may also hold a cached null value. A straight null being returned means that the cache contains no mapping for this key.
    • put

      public void put(Object key, Object value)
      Write the key-value pair to Aerospike database.
      Specified by:
      put in interface Cache
      Parameters:
      key - The key to write.
      value - The value to write.
    • putIfAbsent

      public Cache.ValueWrapper putIfAbsent(Object key, Object value)
      Write the key-value pair to Aerospike database if the key doesn't already exist.
      Specified by:
      putIfAbsent in interface Cache
      Parameters:
      key - The key to write.
      value - The value (bins) to write.
      Returns:
      In case the key already exists return the existing value, else return null.