@ExperimentalApi @ParametersAreNonnullByDefault public interface RequestCache<K,V>
Note that "request" here means a short-lived job including but not limited to HTTP requests and scheduled jobs.
WARNING: Request-scoped caches revert to read-through behaviour if a thread attempts
to access one without first establishing a request context. Under those conditions, calls to
get(Object)
and get(Object, Supplier)
effectively always "miss" and use the
CacheLoader
or Supplier
respectively. This can have a serious performance impact,
so background threads are advised to create a temporary request context explicitly with JiraThreadLocalUtil
when performing JQL queries, examining issue data, or any other significant piece of work.
WARNING: Request caches are effectively unbounded. In the unusual case of a single request examining a large number of issues or any similarly large piece of work, it is strongly recommended that it be broken into batches so that the request caches can be explicitly cleared between the batches.
RequestCacheFactory
Modifier and Type | Method and Description |
---|---|
V |
get(K key)
Retrieves the value for a key by retrieving it from the request cache if possible and by using the
request cache's cache loader, otherwise.
|
V |
get(K key,
com.atlassian.cache.Supplier<V> supplier)
Retrieves the value for a key by retrieving it from the request cache if possible and by using the
specified supplier, otherwise.
|
V |
getIfPresent(K key)
Retrieves the value for a key by retrieving it from the request cache if possible and otherwise giving
up and returning
null . |
void |
remove(K key)
Discards any value cached for the given key.
|
void |
removeAll()
Discards all values from this request cache.
|
@Nonnull V get(K key)
When there is no request-scoped context defined, the request cache is always empty and the value is lazily loaded. If there is a request-scoped context but the value is not yet in the cache, it is lazily loaded and the result is saved to the cache.
key
- the key for which to retrieve a value@Nullable V getIfPresent(K key)
null
.
When there is no request-scoped context defined or if the value is not already in the request cache,
then null
is returned without attempting to load the value.
key
- the key for which to retrieve a value@Nonnull V get(K key, com.atlassian.cache.Supplier<V> supplier)
This is useful when the key used to identify the data does not have enough information to construct
the value or when using it would be less efficient. For example, we may have a whole Issue
available but only want to use its id as the key for the request cache. If the cache loader then
had to use the IssueManager
to reload the issue's data, this would be very wasteful. But the
Supplier
can hold onto the Issue
that we already have and still allow just the id
to be used as the cache key.
When there is no request-scoped context defined, the request cache is always empty and the value is lazily loaded. If there is a request-scoped context but the value is not yet in the cache, it is lazily loaded and the result is saved to the cache.
key
- the key for which to retrieve a valuesupplier
- a supplier that can load the value if it is not in the cache; this will be used instead
of the CacheLoader
supplied when the cache was created. The Supplier
must not
return a null
value.void remove(K key)
key
- the key to be invalidated / removed from the cachevoid removeAll()
Copyright © 2002-2019 Atlassian. All Rights Reserved.