Class CacheMethods


  • public final class CacheMethods
    extends Object
    Extensions methods for using caches with Martini.
    • Method Detail

      • cacheGet

        @GloopParameter(name="value")
        public static <T> T cacheGet​(@GloopParameter(allowNull=false)
                                     String cacheName,
                                     @GloopParameter(allowNull=false)
                                     Object key)
        Get the value of a cache entry using the entry's associated key.
        Parameters:
        cacheName - the name of the cache in the current package
        key - the cache entry's associated key
        Returns:
        the cached value, or null if no value was cached for the provided key
        Throws:
        io.toro.martini.cache.CacheManagerException - if cache couldn't be constructed from cacheName
        Since:
        1.0
      • cacheGet

        @GloopParameter(name="value")
        public static <T> T cacheGet​(@GloopParameter(allowNull=false)
                                     String packageName,
                                     @GloopParameter(allowNull=false)
                                     String cacheName,
                                     @GloopParameter(allowNull=false)
                                     Object key)
        Get the value of a cache entry using the entry's associated key in a specific package
        Parameters:
        packageName - the name of the package you want to get the cache
        cacheName - the name of the cache in the given package
        key - the cache entry's associated key
        Returns:
        the cached value, or null if no value was cached for the provided key
        Throws:
        io.toro.martini.cache.CacheManagerException - if cache couldn't be constructed from cacheName
        Since:
        2.0
      • cacheGet

        @GloopParameter(name="values")
        public static <K,​V> Map<K,​V> cacheGet​(@GloopParameter(allowNull=false)
                                                          String cacheName,
                                                          @GloopParameter(allowNull=false)
                                                          Collection<?> keys)
        Get entries in the cache for the each of the given keys as a map, or an empty map if no values were cached for those keys.
        Parameters:
        cacheName - the name of the cache in the current package
        keys - The keys for the entries that need to be fetched
        Returns:
        the cached values, or an empty map
        Since:
        1.0
      • cacheGet

        @GloopParameter(name="values")
        public static <K,​V> Map<K,​V> cacheGet​(@GloopParameter(allowNull=false)
                                                          String packageName,
                                                          @GloopParameter(allowNull=false)
                                                          String cacheName,
                                                          @GloopParameter(allowNull=false)
                                                          Collection<?> keys)
        Get entries in the cache for the each of the given keys as a map, or an empty map if no values were cached for those keys in a specific package
        Parameters:
        packageName - the name of the package you want to get the cache
        cacheName - the name of the cache in the given package
        keys - The keys for the entries that need to be fetched
        Returns:
        the cached values, or an empty map
        Since:
        2.0
      • cacheGet

        @GloopParameter(name="value")
        public static <T> T cacheGet​(@GloopParameter(allowNull=false)
                                     String cacheName,
                                     @GloopParameter(allowNull=false)
                                     Object key,
                                     @GloopParameter(allowNull=false)
                                     Closure<T> loader)
        Get the value in the cache for the given key, or the value returned by the closure if no value was cached for that key.
        Parameters:
        cacheName - the name of the cache in the current package
        key - the cache entry's associated key
        loader - the closure that loads the value for key if it doesn't exist
        Returns:
        the cached value, or the value returned by the closure
        Since:
        1.0
      • cacheGet

        @GloopParameter(name="value")
        public static <T> T cacheGet​(@GloopParameter(allowNull=false)
                                     String packageName,
                                     @GloopParameter(allowNull=false)
                                     String cacheName,
                                     @GloopParameter(allowNull=false)
                                     Object key,
                                     @GloopParameter(allowNull=false)
                                     Closure<T> loader)
        Get the value in the cache for the given key, or the value returned by the closure if no value was cached for that key.
        Parameters:
        packageName - the name of the package you want to get the cache
        cacheName - the name of the cache in the given package
        key - the cache entry's associated key
        loader - the closure that loads the value for key if it doesn't exist
        Returns:
        the cached value, or the value returned by the closure
        Since:
        2.0
      • cacheGet

        @GloopParameter(name="value")
        public static <T> T cacheGet​(@GloopParameter(allowNull=false)
                                     String cacheName,
                                     @GloopParameter(allowNull=false)
                                     Object key,
                                     T defaultValue)
        Get the value in the cache for the given key, or a provided default value if no value was cached for that key.
        Parameters:
        cacheName - the name of the cache in the current package
        key - the cache entry's associated key
        defaultValue - the value for key if it doesn't exist
        Returns:
        the cached value, or defaultValue if an entry for key does not exist
        Since:
        1.0
      • cacheGet

        @GloopParameter(name="value")
        public static <T> T cacheGet​(@GloopParameter(allowNull=false)
                                     String packageName,
                                     @GloopParameter(allowNull=false)
                                     String cacheName,
                                     @GloopParameter(allowNull=false)
                                     Object key,
                                     T defaultValue)
        Get the value in the cache for the given key, or a provided default value if no value was cached for that key.
        Parameters:
        packageName - the name of the package you want to get the cache
        cacheName - the name of the cache in the given package
        key - the cache entry's associated key
        defaultValue - the value for key if it doesn't exist
        Returns:
        the cached value, or defaultValue if an entry for key does not exist
        Since:
        2.0
      • cachePutAll

        public static void cachePutAll​(@GloopParameter(allowNull=false)
                                       String cacheName,
                                       @GloopParameter(allowNull=false)
                                       Map<?,​?> entries)
        Put the given entries in the cache.
        Parameters:
        cacheName - the name of the cache in the current package
        entries - the entries to put in cache
        Since:
        1.0
      • cacheInvalidate

        public static void cacheInvalidate​(@GloopParameter(allowNull=false)
                                           String cacheName,
                                           @GloopParameter(allowNull=false)
                                           Object key)
        Invalidate the given key in the cache.
        Parameters:
        cacheName - the name of the cache in the current package
        key - the key to invalidate
        Since:
        1.0