Class GuavaCacheStoreAdapter
- java.lang.Object
-
- org.craftercms.core.cache.impl.store.guava.GuavaCacheStoreAdapter
-
- All Implemented Interfaces:
CacheStoreAdapter,org.springframework.beans.factory.DisposableBean
public class GuavaCacheStoreAdapter extends Object implements CacheStoreAdapter, org.springframework.beans.factory.DisposableBean
Implementation of aCacheStoreAdapterusing GuavaCaches.- Author:
- joseross
-
-
Constructor Summary
Constructors Constructor Description GuavaCacheStoreAdapter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddScope(String scope, int maxItemsInMemory)Adds a new scope.voidclearAll()Clears the contents of the entire store.voidclearScope(String scope)Clears the contents of the specified scope in the underlying store.voiddestroy()Destroy method, called by the Spring container.CacheItemget(String scope, Object key)Retrieves an item from a scope.Collection<Object>getKeys(String scope)Returns a list of the keys of the items present in the specified scope.Collection<String>getScopes()Returns the scopes managed by the underlying store.intgetSize(String scope)Returns the quantity of items present in the specified scope.CacheStatisticsgetStatistics(String scope)Returns the statistics of the specified scope from the underlying store.booleanhasKey(String scope, Object key)Returns true if there's and item with the specified key in the specified scope.booleanhasScope(String scope)Returns true if the specified scope exists in the cache.voidput(CacheItem item)Puts an item in a scope.booleanremove(String scope, Object key)Removes an item from a scope.voidremoveScope(String scope)Removes an existing scope and all the items that are in it.
-
-
-
Method Detail
-
destroy
public void destroy()
Destroy method, called by the Spring container. CallsCache.cleanUp()for all instances.- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-
hasScope
public boolean hasScope(String scope)
Description copied from interface:CacheStoreAdapterReturns true if the specified scope exists in the cache.- Specified by:
hasScopein interfaceCacheStoreAdapter
-
getScopes
public Collection<String> getScopes()
Returns the scopes managed by the underlying store.- Specified by:
getScopesin interfaceCacheStoreAdapter
-
addScope
public void addScope(String scope, int maxItemsInMemory)
Adds a new scope. The scope is an instance of Guava'sCache.- Specified by:
addScopein interfaceCacheStoreAdapter- Parameters:
scope- the name of the scopemaxItemsInMemory- the maximum number of items in memory, before they are evicted- Throws:
Exception
-
removeScope
public void removeScope(String scope)
Removes an existing scope and all the items that are in it.- Specified by:
removeScopein interfaceCacheStoreAdapter- Parameters:
scope- scope to remove
-
getSize
public int getSize(String scope)
Returns the quantity of items present in the specified scope.- Specified by:
getSizein interfaceCacheStoreAdapter- Returns:
- the size of the scope (quantity of items)
-
getKeys
public Collection<Object> getKeys(String scope)
Returns a list of the keys of the items present in the specified scope.- Specified by:
getKeysin interfaceCacheStoreAdapter- Returns:
- a list of the keys of the available items in the scope
-
hasKey
public boolean hasKey(String scope, Object key)
Returns true if there's and item with the specified key in the specified scope.- Specified by:
hasKeyin interfaceCacheStoreAdapter- Returns:
- true if the key exists in the scope, false otherwise
-
get
public CacheItem get(String scope, Object key)
Retrieves an item from a scope.- Specified by:
getin interfaceCacheStoreAdapter- Parameters:
scope- scope to get the item fromkey- unique key for the item within this scope- Returns:
- the requested item if found, null otherwise
-
put
public void put(CacheItem item)
Puts an item in a scope. The scope is obtained throughCacheItem.getScope().- Specified by:
putin interfaceCacheStoreAdapter- Parameters:
item- the item to put
-
remove
public boolean remove(String scope, Object key)
Removes an item from a scope.- Specified by:
removein interfaceCacheStoreAdapter- Parameters:
scope- scope to remove the item fromkey- unique key for the item within this scope- Returns:
- true if the removal was successful, false otherwise
-
clearAll
public void clearAll()
Clears the contents of the entire store.- Specified by:
clearAllin interfaceCacheStoreAdapter
-
clearScope
public void clearScope(String scope)
Clears the contents of the specified scope in the underlying store.- Specified by:
clearScopein interfaceCacheStoreAdapter- Parameters:
scope- scope to clear
-
getStatistics
public CacheStatistics getStatistics(String scope)
Returns the statistics of the specified scope from the underlying store.- Specified by:
getStatisticsin interfaceCacheStoreAdapter- Parameters:
scope- scope to inspect- Returns:
- the statistics
-
-