Class Caches


  • public class Caches
    extends Object
    Helper for dealing with Infinispan cache instances.
    Since:
    4.1
    Author:
    Galder ZamarreƱo
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.infinispan.AdvancedCache asyncWriteCache​(org.infinispan.AdvancedCache cache, org.infinispan.context.Flag extraFlag)
      Transform a given cache into a cache that writes cache entries without waiting for them to complete, adding an extra flag.
      static void broadcastEvictAll​(org.infinispan.AdvancedCache cache)
      Broadcast an evict-all command with the given cache instance.
      static <K,​V>
      Caches.MapCollectableCloseableIterable<K,​V>
      entrySet​(org.infinispan.AdvancedCache<K,​V> cache)  
      static <K,​V>
      Caches.MapCollectableCloseableIterable<K,​V>
      entrySet​(org.infinispan.AdvancedCache<K,​V> cache, org.infinispan.filter.KeyValueFilter<K,​V> filter)  
      static <K,​V,​T>
      Caches.MapCollectableCloseableIterable<K,​T>
      entrySet​(org.infinispan.AdvancedCache<K,​V> cache, org.infinispan.filter.KeyValueFilter<K,​V> filter, org.infinispan.filter.Converter<K,​V,​T> converter)  
      static org.infinispan.AdvancedCache failSilentReadCache​(org.infinispan.AdvancedCache cache)
      Transform a given cache into a cache that fails silently if cache reads fail.
      static org.infinispan.AdvancedCache failSilentWriteCache​(org.infinispan.AdvancedCache cache)
      Transform a given cache into a cache that fails silently if cache writes fail.
      static org.infinispan.AdvancedCache failSilentWriteCache​(org.infinispan.AdvancedCache cache, org.infinispan.context.Flag extraFlag)
      Transform a given cache into a cache that fails silently if cache writes fail, adding an extra flag.
      static org.infinispan.AdvancedCache ignoreReturnValuesCache​(org.infinispan.AdvancedCache cache)
      Transform a given cache into a cache that ignores return values for operations returning previous values, i.e.
      static org.infinispan.AdvancedCache ignoreReturnValuesCache​(org.infinispan.AdvancedCache cache, org.infinispan.context.Flag extraFlag)
      Transform a given cache into a cache that ignores return values for operations returning previous values, i.e.
      static boolean isClustered​(org.infinispan.AdvancedCache cache)
      Indicates whether the given cache is configured to cluster its contents.
      static boolean isInvalidationCache​(org.infinispan.AdvancedCache cache)
      Indicates whether the given cache is configured with CacheMode.INVALIDATION_ASYNC or CacheMode.INVALIDATION_SYNC.
      static boolean isSynchronousCache​(org.infinispan.AdvancedCache cache)
      Indicates whether the given cache is configured with CacheMode.REPL_SYNC, CacheMode.INVALIDATION_SYNC, or CacheMode.DIST_SYNC.
      static boolean isTransactionalCache​(org.infinispan.AdvancedCache cache)  
      static org.infinispan.AdvancedCache localCache​(org.infinispan.AdvancedCache cache)
      Transform a given cache into a local cache
      static void removeAll​(org.infinispan.AdvancedCache cache)  
      static void withinTx​(TransactionManager tm, Runnable runnable)  
      static <T> T withinTx​(TransactionManager tm, Callable<T> c)
      Call an operation within a transaction.
      static <T> T withinTx​(org.infinispan.AdvancedCache cache, Callable<T> c)
      Call an operation within a transaction.
    • Method Detail

      • withinTx

        public static <T> T withinTx​(org.infinispan.AdvancedCache cache,
                                     Callable<T> c)
                              throws Exception
        Call an operation within a transaction. This method guarantees that the right pattern is used to make sure that the transaction is always either committed or rollback.
        Type Parameters:
        T - type of callable return
        Parameters:
        cache - instance whose transaction manager to use
        c - callable instance to run within a transaction
        Returns:
        returns whatever the callable returns
        Throws:
        Exception - if any operation within the transaction fails
      • withinTx

        public static <T> T withinTx​(TransactionManager tm,
                                     Callable<T> c)
                              throws Exception
        Call an operation within a transaction. This method guarantees that the right pattern is used to make sure that the transaction is always either committed or rollbacked.
        Type Parameters:
        T - type of callable return
        Parameters:
        tm - transaction manager
        c - callable instance to run within a transaction
        Returns:
        returns whatever the callable returns
        Throws:
        Exception - if any operation within the transaction fails
      • localCache

        public static org.infinispan.AdvancedCache localCache​(org.infinispan.AdvancedCache cache)
        Transform a given cache into a local cache
        Parameters:
        cache - to be transformed
        Returns:
        a cache that operates only in local-mode
      • ignoreReturnValuesCache

        public static org.infinispan.AdvancedCache ignoreReturnValuesCache​(org.infinispan.AdvancedCache cache)
        Transform a given cache into a cache that ignores return values for operations returning previous values, i.e. BasicCache.put(Object, Object)
        Parameters:
        cache - to be transformed
        Returns:
        a cache that ignores return values
      • ignoreReturnValuesCache

        public static org.infinispan.AdvancedCache ignoreReturnValuesCache​(org.infinispan.AdvancedCache cache,
                                                                           org.infinispan.context.Flag extraFlag)
        Transform a given cache into a cache that ignores return values for operations returning previous values, i.e. BasicCache.put(Object, Object), adding an extra flag.
        Parameters:
        cache - to be transformed
        extraFlag - to add to the returned cache
        Returns:
        a cache that ignores return values
      • asyncWriteCache

        public static org.infinispan.AdvancedCache asyncWriteCache​(org.infinispan.AdvancedCache cache,
                                                                   org.infinispan.context.Flag extraFlag)
        Transform a given cache into a cache that writes cache entries without waiting for them to complete, adding an extra flag.
        Parameters:
        cache - to be transformed
        extraFlag - to add to the returned cache
        Returns:
        a cache that writes asynchronously
      • failSilentWriteCache

        public static org.infinispan.AdvancedCache failSilentWriteCache​(org.infinispan.AdvancedCache cache)
        Transform a given cache into a cache that fails silently if cache writes fail.
        Parameters:
        cache - to be transformed
        Returns:
        a cache that fails silently if cache writes fail
      • failSilentWriteCache

        public static org.infinispan.AdvancedCache failSilentWriteCache​(org.infinispan.AdvancedCache cache,
                                                                        org.infinispan.context.Flag extraFlag)
        Transform a given cache into a cache that fails silently if cache writes fail, adding an extra flag.
        Parameters:
        cache - to be transformed
        extraFlag - to be added to returned cache
        Returns:
        a cache that fails silently if cache writes fail
      • failSilentReadCache

        public static org.infinispan.AdvancedCache failSilentReadCache​(org.infinispan.AdvancedCache cache)
        Transform a given cache into a cache that fails silently if cache reads fail.
        Parameters:
        cache - to be transformed
        Returns:
        a cache that fails silently if cache reads fail
      • broadcastEvictAll

        public static void broadcastEvictAll​(org.infinispan.AdvancedCache cache)
        Broadcast an evict-all command with the given cache instance.
        Parameters:
        cache - instance used to broadcast command
      • isInvalidationCache

        public static boolean isInvalidationCache​(org.infinispan.AdvancedCache cache)
        Indicates whether the given cache is configured with CacheMode.INVALIDATION_ASYNC or CacheMode.INVALIDATION_SYNC.
        Parameters:
        cache - to check for invalidation configuration
        Returns:
        true if the cache is configured with invalidation, false otherwise
      • isSynchronousCache

        public static boolean isSynchronousCache​(org.infinispan.AdvancedCache cache)
        Indicates whether the given cache is configured with CacheMode.REPL_SYNC, CacheMode.INVALIDATION_SYNC, or CacheMode.DIST_SYNC.
        Parameters:
        cache - to check for synchronous configuration
        Returns:
        true if the cache is configured with synchronous mode, false otherwise
      • isClustered

        public static boolean isClustered​(org.infinispan.AdvancedCache cache)
        Indicates whether the given cache is configured to cluster its contents. A cache is considered to clustered if it's configured with any cache mode except CacheMode.LOCAL
        Parameters:
        cache - to check whether it clusters its contents
        Returns:
        true if the cache is configured with clustering, false otherwise
      • isTransactionalCache

        public static boolean isTransactionalCache​(org.infinispan.AdvancedCache cache)
      • removeAll

        public static void removeAll​(org.infinispan.AdvancedCache cache)
      • entrySet

        public static <K,​V> Caches.MapCollectableCloseableIterable<K,​V> entrySet​(org.infinispan.AdvancedCache<K,​V> cache,
                                                                                             org.infinispan.filter.KeyValueFilter<K,​V> filter)
      • entrySet

        public static <K,​V,​T> Caches.MapCollectableCloseableIterable<K,​T> entrySet​(org.infinispan.AdvancedCache<K,​V> cache,
                                                                                                     org.infinispan.filter.KeyValueFilter<K,​V> filter,
                                                                                                     org.infinispan.filter.Converter<K,​V,​T> converter)