Class JedisCache<T extends Cacheable>

java.lang.Object
org.deltava.util.cache.Cache<T>
org.deltava.util.cache.JedisCache<T>
Type Parameters:
T - the Cacheable object type
Direct Known Subclasses:
JedisGeoCache

public class JedisCache<T extends Cacheable> extends Cache<T>
An object cache using ValKey as its backing store.
Since:
7.1
Version:
11.5
Author:
Luke
  • Constructor Details

    • JedisCache

      public JedisCache(String bucket, int expiry)
      Creates a new Cache.
      Parameters:
      bucket - the cache key bucket to use
      expiry - the expiration time in seconds
  • Method Details

    • createKey

      protected String createKey(Object key)
      Creates a Jedis bucket:key key.
      Parameters:
      key - the raw key
      Returns:
      the bucket:key key
    • getExpiryTime

      protected long getExpiryTime(T entry)
      Returns the expiration time for a cache entry, based on the cache or the entry's expiration time.
      Parameters:
      entry - the entry
      Returns:
      the time it will expire
    • getErrors

      public long getErrors()
      Description copied from class: Cache
      Returns the total number of cache errors.
      Overrides:
      getErrors in class Cache<T extends Cacheable>
      Returns:
      the number of errors
    • isRemote

      public boolean isRemote()
      Description copied from class: Cache
      Returns if the cache is a remote cache.
      Overrides:
      isRemote in class Cache<T extends Cacheable>
      Returns:
      TRUE if remote, otherwise FALSE
    • addEntry

      protected void addEntry(T entry)
      Description copied from class: Cache
      Adds an entry to the cache. Subclasses need to implement this method to handle cache additions, the public method forces an overflow check.
      Specified by:
      addEntry in class Cache<T extends Cacheable>
      Parameters:
      entry - the entry to add
    • addAll

      public void addAll(Collection<? extends T> entries)
      Description copied from class: Cache
      Adds a number of entries to the cache.
      Overrides:
      addAll in class Cache<T extends Cacheable>
      Parameters:
      entries - a Collection of Cacheable entries
    • addNullEntry

      protected void addNullEntry(Object key)
      Description copied from class: Cache
      Adds a null entry to the cache. Subclasses need to implement this method to handle cache additions, the public method forces an overflow check.
      Specified by:
      addNullEntry in class Cache<T extends Cacheable>
      Parameters:
      key - the entry key
    • contains

      public boolean contains(Object key)
      Description copied from class: Cache
      Returns if the cache contains a particular cache key.
      Overrides:
      contains in class Cache<T extends Cacheable>
      Parameters:
      key - the cache key
      Returns:
      TRUE if the cache contains the key, otherwise FALSE
    • get

      public T get(Object key)
      Description copied from class: Cache
      Retrieves an entry from the cache.
      Specified by:
      get in class Cache<T extends Cacheable>
      Parameters:
      key - the cache key
      Returns:
      the cache entry, or null if the key is not present or the entry is invalid
    • remove

      public void remove(Object key)
      Description copied from class: Cache
      Invalidate a cache entry.
      Overrides:
      remove in class Cache<T extends Cacheable>
      Parameters:
      key - the entry key
    • clear

      public void clear()
      Description copied from class: Cache
      Clears the cache.
      Overrides:
      clear in class Cache<T extends Cacheable>
    • getAll

      public Map<Object,T> getAll(Collection<?> keys)
      Description copied from class: Cache
      Returns multiple objects from the cache.
      Overrides:
      getAll in class Cache<T extends Cacheable>
      Parameters:
      keys - the cache keys
      Returns:
      a Map of results keyed by cache key
    • getMaxSize

      public int getMaxSize()
      This method is repurposed to deliver the round-trip latency to the cache server.
      Overrides:
      getMaxSize in class Cache<T extends Cacheable>
      Returns:
      the latency in nanoseconds
    • size

      public int size()
      Description copied from class: Cache
      Returns the current size of the cache.
      Overrides:
      size in class Cache<T extends Cacheable>
      Returns:
      the number of entries in the cache