Class RequestCacheController
A "request" is any relatively short-lived unit of work, which might be a user's HTTP request,
processing the incoming mail queue, reindexing a batch of issues, etc. The request-scoped
context is managed implicitly for HTTP requests and jobs the run within atlassian-scheduler.
It is also implied by the use of JiraThreadLocalUtil
,
and can alternatively be managed explicitly through this static utility.
- Since:
- v6.4.8
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
clearAll()
Explicitly clears all request caches for the current thread.static void
Exit from a request caching context, destroying it if this context was not nested within another.static boolean
Returnstrue
if a request-scoped caching context has been established.static void
A convenient wrapper for running code within a context that participates in request caching.static void
Establish or re-enter a request caching context.
-
Constructor Details
-
RequestCacheController
public RequestCacheController()
-
-
Method Details
-
startContext
public static void startContext()Establish or re-enter a request caching context.Calls to this method must be paired with the same number of calls to
closeContext()
. If possible, this should be arranged by using atry...finally
that closes the context in thefinally
block. Alternatively,process(Runnable)
will take care of opening and closing the context for you. -
closeContext
public static void closeContext()Exit from a request caching context, destroying it if this context was not nested within another.- Throws:
IllegalStateException
- if no request cache context had been established
-
clearAll
public static void clearAll()Explicitly clears all request caches for the current thread.You probably do not need this. It is intended for extreme cases, such as a data import performed from a user's thread, where it is known that the system's data has been drastically modified from within a single request's scope.
WARNING: This is only effective for the current thread. If you think you need to clear the request caches for all threads, then 1) You're wrong, and 2) That is impossible, anyway.
-
isInContext
public static boolean isInContext()Returnstrue
if a request-scoped caching context has been established. When no request-scoped caching context is established, request caches revert to a read-through behaviour; that is, they will always pass every get request on to their cache loaders.- Returns:
true
if a request-scoped caching context has been established;false
otherwise.
-
process
A convenient wrapper for running code within a context that participates in request caching.If a request-scoped caching context does not currently exist, then one is established for the duration of
runnable
and destroyed afterwards. If a request-scoped caching context has already been established, then there are no special side-effects; that is, the request caches are already available and will not be flushed or destroyed by this method.- Parameters:
runnable
- work to perform within a request-scoped context
-