public class CacheManager extends Object
Is responsible for creating new caches using createCache(String)
. Also, this class keeps track of all
known caches.
Additionally instances of InlineCache
can be created, which can be used to compute a single value,
which is then cached for a given amount of time.
Modifier and Type | Field and Description |
---|---|
protected static Log |
LOG
Logged used by the caching system
|
Modifier and Type | Method and Description |
---|---|
static <K,V> Cache<K,V> |
createCache(String name)
Creates a cached with the given name.
|
static <K,V> Cache<K,V> |
createCache(String name,
ValueComputer<K,V> valueComputer,
ValueVerifier<V> verifier)
Creates a cache with the given name.
|
static <E> InlineCache<E> |
createInlineCache(Duration ttl,
Supplier<E> computer)
Creates a new
InlineCache with the given TTL and computer. |
static <E> InlineCache<E> |
createTenSecondsInlineCache(Supplier<E> computer)
Boilerplate method for
createInlineCache(Duration, Supplier)
which keeps the computed value for up to 10 seconds. |
static List<sirius.kernel.cache.ManagedCache<?,?>> |
getCaches()
Returns a list of all known caches
|
protected static final Log LOG
public static List<sirius.kernel.cache.ManagedCache<?,?>> getCaches()
public static <K,V> Cache<K,V> createCache(String name, ValueComputer<K,V> valueComputer, ValueVerifier<V> verifier)
The name is used to load the settings from the system configuration, using the extension cache.[name]. If a value is absent in the cache, the given valueComputer is used to generate the requested value. If a value is fetched from the cache, it is verified by the given verifier in certain intervals before it is returned to the user.
The system config can provide the following values:
K
- the key field used to identify cache entriesV
- the value type used by the cachename
- the name of the cache, used to load the appropriate extension from the configvalueComputer
- used to compute a value, if no valid value was found in the cache for the given key. Can
be null if there is no appropriate way to compute such a value. In this case, the
cache will simply return null.verifier
- used to verify a value before it is returned to the user. Note that the
value is not verified each time, but in given intervals. If the verifier is null,
no verification will take place.public static <K,V> Cache<K,V> createCache(String name)
This is just a shortcut for createCache(String, ValueComputer, ValueVerifier)
with neither a
ValueComputer nor a ValueVerifier supplied.
K
- the key field used to identify cache entriesV
- the value type used by the cachename
- the name of the cache (used to fetch settings from the system configcreateCache(String, ValueComputer, ValueVerifier)
public static <E> InlineCache<E> createInlineCache(Duration ttl, Supplier<E> computer)
InlineCache
with the given TTL and computer.
An inline cache can be used to compute a single value, which is then cached for a certain amount of time.
E
- the type of values being cachedttl
- specifies the duration which the computed value will be cachedcomputer
- the provider which is used to re-compute the value once it expiredpublic static <E> InlineCache<E> createTenSecondsInlineCache(Supplier<E> computer)
createInlineCache(Duration, Supplier)
which keeps the computed value for up to 10 seconds.E
- the type of values being cachedcomputer
- the provider which is used to re-compute the value once it expiredCopyright © 2018. All rights reserved.