Class CacheView<KF,KB,V>

java.lang.Object
org.aksw.commons.util.cache.CacheView<KF,KB,V>
Type Parameters:
KF - The frontend key type
KB - The backend key type
V - The value type
All Implemented Interfaces:
com.google.common.cache.Cache<KF,V>

public class CacheView<KF,KB,V> extends Object implements com.google.common.cache.Cache<KF,V>
A view over a cache which can place 'local' keys into a shared cache. For example, local keys could be offsets in a file, whereas global keys include the file name.
  • Field Details

    • backend

      protected com.google.common.cache.Cache<KB,V> backend
      The delegate cache
    • keyConverter

      protected com.google.common.base.Converter<KF,KB> keyConverter
    • backendKeyFilter

      protected Predicate<KB> backendKeyFilter
      A predicate that hides cache entries unrelated to this cache view. Note that every backend key derived from this view must succeed the filter. This means: backendFilter.test(keyMapper.convert(frontendKey)) must always evaluate to true.
  • Constructor Details

    • CacheView

      public CacheView(com.google.common.cache.Cache<KB,V> backend, com.google.common.base.Converter<KF,KB> keyConverter, Predicate<KB> backendFilter)
  • Method Details

    • getBackend

      public com.google.common.cache.Cache<KB,V> getBackend()
    • safeToBackend

      protected KB safeToBackend(KF key)
    • convert

      protected List<KB> convert(Object key)
    • getIfPresent

      public V getIfPresent(Object key)
      Specified by:
      getIfPresent in interface com.google.common.cache.Cache<KF,KB>
    • get

      public V get(KF key, Callable<? extends V> loader) throws ExecutionException
      Specified by:
      get in interface com.google.common.cache.Cache<KF,KB>
      Throws:
      ExecutionException
    • getAllPresent

      public com.google.common.collect.ImmutableMap<KF,V> getAllPresent(Iterable<? extends Object> keys)
      Specified by:
      getAllPresent in interface com.google.common.cache.Cache<KF,KB>
    • put

      public void put(KF key, V value)
      Specified by:
      put in interface com.google.common.cache.Cache<KF,KB>
    • putAll

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

      public void invalidate(Object key)
      Specified by:
      invalidate in interface com.google.common.cache.Cache<KF,KB>
    • invalidateAll

      public void invalidateAll(Iterable<? extends Object> keys)
      Specified by:
      invalidateAll in interface com.google.common.cache.Cache<KF,KB>
    • invalidateAll

      public void invalidateAll()
      Specified by:
      invalidateAll in interface com.google.common.cache.Cache<KF,KB>
    • size

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

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

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

      public void cleanUp()
      Specified by:
      cleanUp in interface com.google.common.cache.Cache<KF,KB>