Class MapCacheStoreAdapter
java.lang.Object
org.craftercms.core.cache.impl.store.MapCacheStoreAdapter
- All Implemented Interfaces:
CacheStoreAdapter
Implementation of a
CacheStoreAdapter
using an underlying Map
.- Author:
- Sumer Jabri, Alfonso Vásquez
-
Constructor Summary
ConstructorDescriptionDefault constructor.MapCacheStoreAdapter
(List<String> scopes) Constructor that receives a list of scopes that need to created. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a new scope.void
clearAll()
Clears the contents of the entire store.void
clearScope
(String scope) Clears the contents of the specified scope in the underlying store.Retrieves an item from a scope.Returns a list of the keys of the items present in the specified scope.Returns the scopes managed by the underlying store.int
Returns the quantity of items present in the specified scope.getStatistics
(String scope) Returns the statistics of the specified scope from the underlying store.boolean
Returns true if there's and item with the specified key in the specified scope.boolean
Returns true if the specified scope exists in the cache.void
Puts an item in a scope.boolean
Removes an item from a scope.void
removeScope
(String scope) Removes an existing scope and all the items that are in it.
-
Constructor Details
-
MapCacheStoreAdapter
public MapCacheStoreAdapter()Default constructor. CreatesscopeCaches
as aConcurrentHashMap
-
MapCacheStoreAdapter
Constructor that receives a list of scopes that need to created. Each scope is an instance ofConcurrentHashMap
.
-
-
Method Details
-
hasScope
Returns true if the specified scope exists in the cache.- Specified by:
hasScope
in interfaceCacheStoreAdapter
- Throws:
Exception
-
getScopes
Returns the scopes managed by the underlying store.- Specified by:
getScopes
in interfaceCacheStoreAdapter
- Throws:
Exception
-
addScope
Adds a new scope. The scope is an instance ofConcurrentHashMap
.- Specified by:
addScope
in interfaceCacheStoreAdapter
- Parameters:
scope
- the name of the scopemaxItemsInMemory
- the maximum number of items in memory, before they are evicted- Throws:
Exception
-
removeScope
Removes an existing scope and all the items that are in it.- Specified by:
removeScope
in interfaceCacheStoreAdapter
- Parameters:
scope
- scope to remove- Throws:
Exception
-
getSize
Returns the quantity of items present in the specified scope.- Specified by:
getSize
in interfaceCacheStoreAdapter
- Returns:
- the size of the scope (quantity of items)
- Throws:
Exception
-
getKeys
Returns a list of the keys of the items present in the specified scope.- Specified by:
getKeys
in interfaceCacheStoreAdapter
- Returns:
- a list of the keys of the available items in the scope
- Throws:
Exception
-
hasKey
Returns true if there's and item with the specified key in the specified scope.- Specified by:
hasKey
in interfaceCacheStoreAdapter
- Returns:
- true if the key exists in the scope, false otherwise
- Throws:
Exception
-
get
Retrieves an item from a scope.- Specified by:
get
in 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
- Throws:
Exception
-
put
Puts an item in a scope. The scope is obtained throughCacheItem.getScope()
.- Specified by:
put
in interfaceCacheStoreAdapter
- Parameters:
item
- the item to put- Throws:
Exception
-
remove
Removes an item from a scope.- Specified by:
remove
in 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
- Throws:
Exception
-
clearAll
Clears the contents of the entire store.- Specified by:
clearAll
in interfaceCacheStoreAdapter
- Throws:
Exception
-
clearScope
Clears the contents of the specified scope in the underlying store.- Specified by:
clearScope
in interfaceCacheStoreAdapter
- Parameters:
scope
- scope to clear- Throws:
Exception
-
getStatistics
Returns the statistics of the specified scope from the underlying store.- Specified by:
getStatistics
in interfaceCacheStoreAdapter
- Parameters:
scope
- scope to inspect- Returns:
- the statistics
-