Class AlwaysInvalidatingCacheDecorator<K,​V>

  • All Implemented Interfaces:
    com.google.common.base.Function<K,​V>, com.google.common.cache.Cache<K,​V>, com.google.common.cache.LoadingCache<K,​V>, Function<K,​V>
    Direct Known Subclasses:
    AlwaysInvalidatingCacheDecorator

    public class AlwaysInvalidatingCacheDecorator<K,​V>
    extends Object
    implements com.google.common.cache.LoadingCache<K,​V>
    This decorator ensures that when invalidate() is called while CacheLoader.load() is being executed, the loaded value will be invalidated. Both get() and invalidate() share the same exclusive reentrant lock, thus making it safe to call invalidate from within load() method. If invalidate() is called during get(), get() will be retried. This will happen only once, a subsequent attempt to invalidate during get() will result in a IllegalStateException. Note: invalidateAll() cannot be called from get().
    • Constructor Detail

      • AlwaysInvalidatingCacheDecorator

        public AlwaysInvalidatingCacheDecorator​(com.google.common.cache.LoadingCache<K,​V> cache)
    • Method Detail

      • refresh

        public void refresh​(K key)
        Specified by:
        refresh in interface com.google.common.cache.LoadingCache<K,​V>
      • putAll

        public void putAll​(Map<? extends K,​? extends V> m)
        Specified by:
        putAll in interface com.google.common.cache.Cache<K,​V>
      • getIfPresent

        @Nullable
        public V getIfPresent​(Object key)
        Specified by:
        getIfPresent in interface com.google.common.cache.Cache<K,​V>
      • getAllPresent

        public com.google.common.collect.ImmutableMap<K,​V> getAllPresent​(@NotNull
                                                                               @NotNull Iterable<?> keys)
        Specified by:
        getAllPresent in interface com.google.common.cache.Cache<K,​V>
      • getUnchecked

        public V getUnchecked​(@NotNull
                              K key)
        Specified by:
        getUnchecked in interface com.google.common.cache.LoadingCache<K,​V>
      • apply

        public V apply​(@NotNull
                       K key)
        Specified by:
        apply in interface com.google.common.base.Function<K,​V>
        Specified by:
        apply in interface Function<K,​V>
        Specified by:
        apply in interface com.google.common.cache.LoadingCache<K,​V>
      • invalidate

        public void invalidate​(@NotNull
                               @NotNull Object key)
        Specified by:
        invalidate in interface com.google.common.cache.Cache<K,​V>
      • invalidateAll

        public void invalidateAll()
        Specified by:
        invalidateAll in interface com.google.common.cache.Cache<K,​V>
      • invalidateAll

        public void invalidateAll​(@NotNull
                                  @NotNull Iterable<?> objects)
        Specified by:
        invalidateAll in interface com.google.common.cache.Cache<K,​V>
      • size

        public long size()
        Specified by:
        size in interface com.google.common.cache.Cache<K,​V>
      • stats

        public com.google.common.cache.CacheStats stats()
        Specified by:
        stats in interface com.google.common.cache.Cache<K,​V>
      • asMap

        public ConcurrentMap<K,​V> asMap()
        Specified by:
        asMap in interface com.google.common.cache.Cache<K,​V>
        Specified by:
        asMap in interface com.google.common.cache.LoadingCache<K,​V>
      • cleanUp

        public void cleanUp()
        Specified by:
        cleanUp in interface com.google.common.cache.Cache<K,​V>
      • put

        public void put​(@NotNull
                        K k,
                        @NotNull
                        V v)
        Specified by:
        put in interface com.google.common.cache.Cache<K,​V>
      • wrap

        public static <K,​V> com.google.common.cache.LoadingCache<K,​V> wrap​(com.google.common.cache.LoadingCache<K,​V> cache)