-
- All Known Implementing Classes:
MockCache
public interface CacheThis class manages object caching. An object is cached mainly for read performance and database offloading. The cache can also be used to store transient data which is shared among all nodes of the system.- Author:
- Alex Bogdanovski [alex@erudika.com]
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleancontains(String id)Do we have this object in the cache?booleancontains(String appid, String id)Do we have this object in the cache?<T> Tget(String id)Read an object from cache.<T> Tget(String appid, String id)Read an object from cache.<T> Map<String,T>getAll(String appid, List<String> ids)Read a number of objects given a list of their ids.<T> Map<String,T>getAll(List<String> ids)Read a number of objects given a list of their ids.<T> voidput(String appid, String id, T object)Store an object in the cache.<T> voidput(String appid, String id, T object, Long ttlSeconds)Store an object in the cache.<T> voidput(String id, T object)Store an object in the cache.<T> voidputAll(String appid, Map<String,T> objects)Store all objects in cache, except those which are null.<T> voidputAll(Map<String,T> objects)Store all objects in cache, except those which are null.voidremove(String id)Remove an object from cache.voidremove(String appid, String id)Remove an object from cache.voidremoveAll()Clears the cache.voidremoveAll(String appid)Clears the cache.voidremoveAll(String appid, List<String> ids)Remove a number of objects from cache given a list of their ids.voidremoveAll(List<String> ids)Remove a number of objects from cache given a list of their ids.
-
-
-
Method Detail
-
contains
boolean contains(String id)
Do we have this object in the cache?- Parameters:
id- the object's id- Returns:
- true if in cache
-
contains
boolean contains(String appid, String id)
Do we have this object in the cache?- Parameters:
appid- the name of the applicationid- the object's id- Returns:
- true if in cache
- See Also:
contains(java.lang.String)
-
put
<T> void put(String id, T object)
Store an object in the cache.- Type Parameters:
T- the type of object to be cached- Parameters:
id- the object's id, not null or emptyobject- the object itself, not null
-
put
<T> void put(String appid, String id, T object)
Store an object in the cache.- Type Parameters:
T- the type of object to be cached- Parameters:
appid- the name of the applicationid- the object's id, not null or emptyobject- the object itself, not null- See Also:
put(java.lang.String, java.lang.Object)
-
put
<T> void put(String appid, String id, T object, Long ttlSeconds)
Store an object in the cache.- Type Parameters:
T- the type of object to be cached- Parameters:
appid- the name of the applicationid- the object's id, not null or emptyobject- the object itself, not nullttlSeconds- the time to live for an object before it is evicted from the cache.- See Also:
put(java.lang.String, java.lang.Object)
-
putAll
<T> void putAll(Map<String,T> objects)
Store all objects in cache, except those which are null.- Type Parameters:
T- any object, not null- Parameters:
objects- map of id - object
-
putAll
<T> void putAll(String appid, Map<String,T> objects)
Store all objects in cache, except those which are null.- Type Parameters:
T- any object, not null- Parameters:
appid- the name of the applicationobjects- map of id - object- See Also:
putAll(java.util.Map)
-
get
<T> T get(String id)
Read an object from cache.- Type Parameters:
T- the type of object to be cached- Parameters:
id- the object's id, not null or empty- Returns:
- the object from cache or null if not found
-
get
<T> T get(String appid, String id)
Read an object from cache.- Type Parameters:
T- the type of object to be cached- Parameters:
appid- the name of the applicationid- the object's id, not null or empty- Returns:
- the object from cache or null if not found
- See Also:
get(java.lang.String)
-
getAll
<T> Map<String,T> getAll(List<String> ids)
Read a number of objects given a list of their ids.- Type Parameters:
T- the type of object to be cached- Parameters:
ids- the ids, not null or empty- Returns:
- a map of the objects that are contained in cache (may be empty)
-
getAll
<T> Map<String,T> getAll(String appid, List<String> ids)
Read a number of objects given a list of their ids.- Type Parameters:
T- the type of object to be cached- Parameters:
appid- the name of the applicationids- the ids, not null or empty- Returns:
- a map of the objects that are contained in cache (may be empty)
- See Also:
getAll(java.util.List)
-
remove
void remove(String id)
Remove an object from cache.- Parameters:
id- the object's id, not null or empty
-
remove
void remove(String appid, String id)
Remove an object from cache.- Parameters:
appid- the name of the applicationid- the object's id, not null or empty- See Also:
remove(java.lang.String)
-
removeAll
void removeAll()
Clears the cache.
-
removeAll
void removeAll(String appid)
Clears the cache.- Parameters:
appid- the name of the application- See Also:
removeAll()
-
removeAll
void removeAll(List<String> ids)
Remove a number of objects from cache given a list of their ids.- Parameters:
ids- the ids, not null or empty
-
removeAll
void removeAll(String appid, List<String> ids)
Remove a number of objects from cache given a list of their ids.- Parameters:
ids- the ids, not null or emptyappid- the name of the application- See Also:
removeAll(java.util.List)
-
-