Class ClusterCaches

java.lang.Object
com.kingsrook.qqq.backend.core.cluster.ClusterCaches

public final class ClusterCaches extends Object
The registry of in-memory caches (static Memoizations and the like). When a cache goes stale on one node, it is cleared on every node: ClusterBus event memo-invalidate, and for session-keyed caches also session-ended. Every static cache registers, inline where it is declared:
 private static final Memoization<Integer, Script> SCRIPTS = ClusterCaches.shared("scripts.byId", new Memoization<>(), Integer::valueOf);
 private static final Memoization<String, Constructor<?>> CTORS = ClusterCaches.nodeLocal(new Memoization<>(), "classes are the same on every node");
 
ClusterCacheAudit, used by tests, fails on a static Memoization that did not register.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Clear a cache on every node.
    static void
    Clear one key of a cache on every node (null key: all of it).
    static boolean
    Whether a cache object was registered (shared or node-local).
    static <T> T
    nodeLocal(T cache, String reason)
    Declare a cache that is correct per node: it holds what is the same on every node (classes, code, provider metadata).
    static void
    sessionEnded(String sessionUUID)
    A session ended: clear session-keyed caches on every node.
    static <V> Memoization<String,V>
    sessionKeyed(String name, Memoization<String,V> memoization)
    Register a shared cache keyed by session UUID: also cleared (for that session) when a session ends on any node.
    static <K, V> Memoization<K,V>
    shared(String name, Memoization<K,V> memoization, Function<String,K> keyParser)
    Register a cache that must be cleared on every node when it is invalidated. keyParser turns an event's key text back into the cache's key type (null: a key invalidation clears everything).
    static <T> T
    shared(String name, T cache, Runnable clearAll, Consumer<String> clearKey)
    Register any other in-memory cache by its clear actions (clearKey may be null: then a key invalidation clears everything).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • shared

      public static <K, V> Memoization<K,V> shared(String name, Memoization<K,V> memoization, Function<String,K> keyParser)
      Register a cache that must be cleared on every node when it is invalidated. keyParser turns an event's key text back into the cache's key type (null: a key invalidation clears everything). Returns the memoization.
    • sessionKeyed

      public static <V> Memoization<String,V> sessionKeyed(String name, Memoization<String,V> memoization)
      Register a shared cache keyed by session UUID: also cleared (for that session) when a session ends on any node.
    • shared

      public static <T> T shared(String name, T cache, Runnable clearAll, Consumer<String> clearKey)
      Register any other in-memory cache by its clear actions (clearKey may be null: then a key invalidation clears everything).
    • nodeLocal

      public static <T> T nodeLocal(T cache, String reason)
      Declare a cache that is correct per node: it holds what is the same on every node (classes, code, provider metadata). The reason documents why.
    • isRegistered

      public static boolean isRegistered(Object cache)
      Whether a cache object was registered (shared or node-local).
    • invalidate

      public static void invalidate(String name)
      Clear a cache on every node.
    • invalidateKey

      public static void invalidateKey(String name, String key)
      Clear one key of a cache on every node (null key: all of it).
    • sessionEnded

      public static void sessionEnded(String sessionUUID)
      A session ended: clear session-keyed caches on every node.