Class RequestCacheController

java.lang.Object
com.atlassian.jira.cache.request.RequestCacheController

public class RequestCacheController extends Object
Utility class for explicitly managing request-scoped context.

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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    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
    Returns true if a request-scoped caching context has been established.
    static void
    process(Runnable runnable)
    A convenient wrapper for running code within a context that participates in request caching.
    static void
    Establish or re-enter a request caching context.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 a try...finally that closes the context in the finally 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()
      Returns true 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

      public static void process(Runnable runnable)
      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