Class BaseCache<V>
java.lang.Object
io.github.emcw.caching.BaseCache<V>
-
Constructor Summary
ConstructorsConstructorDescriptionBaseCache
(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 theCacheStrategy
of the givenoptions
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Reports whether the cache contains no entries.getAll()
Returns a thread-safe view of this cache as aMap
.
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 callinggetAll()
and filtering out any that aren't inkeys
, 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 isTIME_BASED
, this method is called automatically at the interval defined inoptions
which was set when it was built.
-
Constructor Details
-
BaseCache
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 theCacheStrategy
of the givenoptions
.- Parameters:
cacheOptions
- The options that this cache will be setup with.- See Also:
-
-
Method Details
-
getAll
-
getMultiple
Returns a new list containing only the values of the specified keys by callinggetAll()
and filtering out any that aren't inkeys
, then getting the values of those left as a list.
For a small amount of keys, callinggetSingle(java.lang.String)
for each one may be quicker than filtering.
Some subclasses may override this to implement additional behaviour. -
getSingle
-
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 isTIME_BASED
, this method is called automatically at the interval defined inoptions
which was set when it was built.- See Also:
-
fetchCacheData
-