Class ThreadScopedCaches

    • Constructor Detail

      • ThreadScopedCaches

        public ThreadScopedCaches()
    • Method Detail

      • getValue

        public static <K,​V> V getValue​(ThreadScopedCaches.Key<K,​V> cacheKey,
                                             K key,
                                             Supplier<? extends V> supplier)
        Returns the value called by supplier.get or a previously cached value. The cache is scoped to the current request and will be cleared at the end of the request. No caching will apply if invoked outside a request. No caching will apply within a mutative request.
        Parameters:
        cacheKey - a key to identify the cache
        key - a sub-key to cache the specific value under
        supplier - will be called to return the object the
        Returns:
        the result of supplier.get()
        Throws:
        RuntimeException - if thrown by supplier.get()
      • inCachingScope

        public static void inCachingScope​(Runnable runnable)
      • inCachingScope

        public static <T> T inCachingScope​(Supplier<T> supplier)
      • makeKey

        public static <K,​V> ThreadScopedCaches.Key<K,​V> makeKey​(Class<?> aClass)
        The returned keys rely on identity comparison. You can have multiple such keys per class but each Key instance creates a separate cache.