Package io.toro.martini
Class CacheMethods
- java.lang.Object
-
- io.toro.martini.CacheMethods
-
public final class CacheMethods extends Object
Extensions methods for using caches with Martini.
-
-
Constructor Summary
Constructors Constructor Description CacheMethods(MartiniPackageProvider provider)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TcacheGet(String cacheName, Object key)Get the value of a cache entry using the entry's associated key.static <T> TcacheGet(String cacheName, Object key, 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.static <T> TcacheGet(String cacheName, 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.static <T> TcacheGet(String packageName, String cacheName, Object key)Get the value of a cache entry using the entry's associated key in a specific packagestatic <T> TcacheGet(String packageName, String cacheName, Object key, 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.static <T> TcacheGet(String packageName, String cacheName, 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.static <K,V>
Map<K,V>cacheGet(String packageName, String cacheName, 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 packagestatic <K,V>
Map<K,V>cacheGet(String cacheName, 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.static voidcacheInvalidate(String cacheName, Object key)Invalidate the given key in the cache.static voidcacheInvalidate(String packageName, String cacheName, Object key)Invalidate the given key in the cache.static voidcacheInvalidateAll(String packageName, String cacheName, Collection<?> keys)Invalidate the given keys in the cache.static voidcacheInvalidateAll(String cacheName, Collection<?> keys)Invalidate the given keys in the cache.static voidcachePut(String cacheName, Object key, Object value)Put the value in the cache, and assign it to the given key.static voidcachePut(String packageName, String cacheName, Object key, Object value)Put the value in the cache, and assign it to the given key.static voidcachePutAll(String packageName, String cacheName, Map<?,?> entries)Put the given entries in the cache.static voidcachePutAll(String cacheName, Map<?,?> entries)Put the given entries in the cache.
-
-
-
Constructor Detail
-
CacheMethods
public CacheMethods(MartiniPackageProvider provider)
-
-
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 packagekey- the cache entry's associated key- Returns:
- the cached value, or
nullif no value was cached for the provided key - Throws:
io.toro.martini.cache.CacheManagerException- if cache couldn't be constructed fromcacheName- 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 cachecacheName- the name of the cache in the given packagekey- the cache entry's associated key- Returns:
- the cached value, or
nullif no value was cached for the provided key - Throws:
io.toro.martini.cache.CacheManagerException- if cache couldn't be constructed fromcacheName- 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 packagekeys- 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 cachecacheName- the name of the cache in the given packagekeys- 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 packagekey- the cache entry's associated keyloader- the closure that loads the value forkeyif 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 cachecacheName- the name of the cache in the given packagekey- the cache entry's associated keyloader- the closure that loads the value forkeyif 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 packagekey- the cache entry's associated keydefaultValue- the value forkeyif it doesn't exist- Returns:
- the cached value, or
defaultValueif an entry forkeydoes 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 cachecacheName- the name of the cache in the given packagekey- the cache entry's associated keydefaultValue- the value forkeyif it doesn't exist- Returns:
- the cached value, or
defaultValueif an entry forkeydoes not exist - Since:
- 2.0
-
cachePut
public static void cachePut(@GloopParameter(allowNull=false) String cacheName, @GloopParameter(allowNull=false) Object key, @GloopParameter(allowNull=false) Object value)
Put the value in the cache, and assign it to the given key.- Parameters:
cacheName- the name of the cache in the current packagekey- the cache keyvalue- the cache value- Since:
- 1.0
-
cachePut
public static void cachePut(@GloopParameter(allowNull=false) String packageName, @GloopParameter(allowNull=false) String cacheName, @GloopParameter(allowNull=false) Object key, @GloopParameter(allowNull=false) Object value)
Put the value in the cache, and assign it to the given key.- Parameters:
packageName- the name of the package you want to put the cachecacheName- the name of the cache in the given packagekey- the cache keyvalue- the cache value- 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 packageentries- the entries to put in cache- Since:
- 1.0
-
cachePutAll
public static void cachePutAll(@GloopParameter(allowNull=false) String packageName, @GloopParameter(allowNull=false) String cacheName, @GloopParameter(allowNull=false) Map<?,?> entries)
Put the given entries in the cache.- Parameters:
packageName- the name of the package you want to put the cachecacheName- the name of the cache in the given packageentries- the entries to put in cache- Since:
- 2.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 packagekey- the key to invalidate- Since:
- 1.0
-
cacheInvalidate
public static void cacheInvalidate(@GloopParameter(allowNull=false) String packageName, @GloopParameter(allowNull=false) String cacheName, @GloopParameter(allowNull=false) Object key)
Invalidate the given key in the cache.- Parameters:
packageName- the name of the package you want to put the cachecacheName- the name of the cache in the given packagekey- the key to invalidate- Since:
- 2.0
-
cacheInvalidateAll
public static void cacheInvalidateAll(@GloopParameter(allowNull=false) String cacheName, @GloopParameter(allowNull=false) Collection<?> keys)
Invalidate the given keys in the cache.- Parameters:
cacheName- the name of the cache in the current packagekeys- the keys to invalidate- Since:
- 1.0
-
cacheInvalidateAll
public static void cacheInvalidateAll(@GloopParameter(allowNull=false) String packageName, @GloopParameter(allowNull=false) String cacheName, @GloopParameter(allowNull=false) Collection<?> keys)
Invalidate the given keys in the cache.- Parameters:
packageName- the name of the package you want to put the cachecacheName- the name of the cache in the given packagekeys- the keys to invalidate- Since:
- 2.0
-
-