Class BaseCache<V>

java.lang.Object
io.github.emcw.caching.BaseCache<V>
Direct Known Subclasses:
Nations, Players, Residents, Towns

public abstract class BaseCache<V> extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
    BaseCache(CacheOptions cacheOptions)
    Abstract class acting as a parent to other cache classes and holds a reference to a Caffeine cache.
    It provides the fundamental methods (getAll, getSingle invalid input: '&' getMultiple) that children automatically inherit.

    It also initializes the scheduler which updates or expires data based on the CacheStrategy of the given options.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Reports whether the cache contains no entries.
    protected abstract Map<String,V>
     
    Returns a thread-safe view of this cache as a Map.

    Some subclasses may override this to implement additional behaviour.
    getMultiple(String @NotNull ... keys)
    Returns a new list containing only the values of the specified keys by calling getAll() and filtering out any that aren't in keys, then getting the values of those left as a list.
    Attempts to get a single element from the cache.
    void
    Always updates the cache, regardless of whether it has expired.

    If this cache is TIME_BASED, this method is called automatically at the interval defined in options which was set when it was built.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BaseCache

      public BaseCache(CacheOptions cacheOptions)
      Abstract class acting as a parent to other cache classes and holds a reference to a Caffeine cache.
      It provides the fundamental methods (getAll, getSingle invalid input: '&' getMultiple) that children automatically inherit.

      It also initializes the scheduler which updates or expires data based on the CacheStrategy of the given options.
      Parameters:
      cacheOptions - The options that this cache will be setup with.
      See Also:
  • Method Details

    • getAll

      public Map<String,V> getAll()
      Returns a thread-safe view of this cache as a Map.

      Some subclasses may override this to implement additional behaviour.
    • getMultiple

      public List<V> getMultiple(String @NotNull ... keys)
      Returns a new list containing only the values of the specified keys by calling getAll() and filtering out any that aren't in keys, then getting the values of those left as a list.

      For a small amount of keys, calling getSingle(java.lang.String) for each one may be quicker than filtering.

      Some subclasses may override this to implement additional behaviour.
    • getSingle

      @Nullable public V getSingle(String key)
      Attempts to get a single element from the cache. Returns null if no such element exists with the given key.

      Some subclasses may override this to implement additional behaviour.
    • cacheIsEmpty

      public boolean cacheIsEmpty()
      Reports whether the cache contains no entries.
      Returns:
      true if the underlying map contains no key-value mappings
    • updateCache

      public void updateCache()
      Always updates the cache, regardless of whether it has expired.

      If this cache is TIME_BASED, this method is called automatically at the interval defined in options which was set when it was built.
      See Also:
    • fetchCacheData

      protected abstract Map<String,V> fetchCacheData()