Class RedisCache

java.lang.Object
overit.geocall.cache.Cache
overit.geocall.cache.RedisCache
All Implemented Interfaces:
AutoCloseable

public class RedisCache extends Cache
Implementation of a cached based on Redis server; All the entries will be saved and retrieved to and from a remote Redis server.
  • Field Details

    • rdb

      protected RedisDB rdb
    • mustWrite

      protected boolean mustWrite
  • Constructor Details

    • RedisCache

      public RedisCache(String keyPrefix, RedisDB rdb)
      Create cache that leverages the passed redis database to store and retrieve the cached values
      Parameters:
      keyPrefix - the prefix af all the key cached
      rdb - redis database's connector instance
  • Method Details

    • remove

      protected boolean remove(String key)
      Locally removes a key from the cache
      If the remove has been success, it notify all the remote listeners
      Specified by:
      remove in class Cache
      Parameters:
      key - the key of the entry to be removed
      Returns:
      true if the key has been removed, false if the key was absent
    • put

      public <T, S> void put(Entry<T,S> entry)
      Locally stores an item inside the cache
      If the put has been success, it notify all the remote listeners
      Specified by:
      put in class Cache
      Type Parameters:
      T - the type of the raw data contained in the cache item
      S - the type of the computed data contained in the cache item
      Parameters:
      entry - the item to be stored
    • clear

      protected boolean clear()
      Clears all the cache
      If the clear has been success, it notify all the remote listeners
      Specified by:
      clear in class Cache
      Returns:
      true if the cache has been cleaned, false if the cache was empty
    • fetch

      public <T, S> Item<T,S> fetch(Entry<T,S> entry)
      Description copied from class: Cache
      Extracts data from cache, or fetches and caches data from the parent cache. If the parent cache is missing it can use the Entry.load() to load the real data.
      Specified by:
      fetch in class Cache
      Type Parameters:
      T - the type of the raw data contained in the cache item
      S - the type of the computed data contained in the cache item
      Parameters:
      entry - the cache's entry to look for
      Returns:
      the data contained in cache, on the parent cache, or potentially loaded and cached
    • keys

      public Set<String> keys()
      Description copied from class: Cache
      Returns the keys stored inside the cache
      Specified by:
      keys in class Cache
      Returns:
      the keys stored inside the cache or an empty set if there's none.
    • get

      public <T, S> Item<T,S> get(Entry<T,S> entry)
      Description copied from class: Cache
      Locally retrieve the data, without search in the parent cache if the entry has not been found.
      Specified by:
      get in class Cache
      Type Parameters:
      T - the type of the raw data contained in the cache item
      S - the type of the computed data contained in the cache item
      Parameters:
      entry - the cache's entry to look for
      Returns:
      the data contained in cache or null if not present
    • getInfo

      public List<Cache.Info> getInfo(String key)
      Description copied from class: Cache
      Return the information about the cache's entries related to the passed key. Each element contains the information about a specific view for that entry.
      Specified by:
      getInfo in class Cache
      Parameters:
      key - the key of the entry
      Returns:
      the list containing the information, or an empty list the there's no information related to the passed key