Class CaffeineCache

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

public class CaffeineCache extends Cache
Class that implements a cache whose entries are been stored in memory.
  • Field Details

    • caches

      protected static final Set<CaffeineCache> caches
    • cache

      protected com.github.benmanes.caffeine.cache.Cache<String,overit.geocall.cache.CaffeineCache.Views> cache
  • Constructor Details

    • CaffeineCache

      public CaffeineCache(@Nullable Cache parent)
      Create a new instance of the cache referred to the passed parent cache
      Parameters:
      parent - the optional parent cache used to propagate the cache changing and retrieve the missing cache values
    • CaffeineCache

      public CaffeineCache(String keyPrefix, @Nullable Cache parent)
      Create a new instance of the cache working with a soma-prefix keys and possibly referring a parent cache
      Parameters:
      keyPrefix - the prefix af all the key cached
      parent - the optional parent cache used to propagate the cache changing and retrieve the missing cache values
  • Method Details

    • 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
    • put

      public <T, S> void put(Entry<T,S> entry)
      Description copied from class: Cache
      Locally stores an item inside the cache
      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
    • finalize

      public void finalize() throws Throwable
      Overrides:
      finalize in class Cache
      Throws:
      Throwable
    • close

      public void close()
      Description copied from class: Cache
      Close the cache and disconnects from the parent
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class Cache
    • remove

      protected boolean remove(String key)
      Description copied from class: Cache
      Locally removes a key from the cache
      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
    • clear

      protected boolean clear()
      Description copied from class: Cache
      Clears all the cache
      Specified by:
      clear in class Cache
      Returns:
      true if the cache has been cleaned, false if the cache was empty
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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