Package org.craftercms.core.cache
Interface Cache
- All Known Implementing Classes:
CacheImpl
public interface Cache
Crafter's Cache API.
- Author:
- Sumer Jabri, Alfonso Vásquez
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a new scope to the cache.void
clearAll()
Clears the contents of the entire cache.void
clearScope
(String scope) Clears the contents of the specified scope in the cache.Retrieves an item from a scope.Returns a list of the keys of the items present in the specified scope.Returns the list of scopes this cache manages.int
Returns the quantity of items present in the specified scope.getStatistics
(String scope) Returns the statistics of the specified scope in the cache.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.void
put
(String scope, Object key, Object value, long expireAfter, long refreshFrequency, CacheLoader loader, Object... loaderParams) Puts and 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.
-
Method Details
-
hasScope
Returns true if the specified scope exists in the cache.- Parameters:
scope
- the name of the scope- Returns:
- true if the specified scope exists in the cache
- Throws:
InternalCacheEngineException
- if an error occurred in the underlying cache implementation
-
getScopes
Returns the list of scopes this cache manages.- Returns:
- the list of available scopes in the cache
- Throws:
InternalCacheEngineException
- if an error occurred in the underlying cache implementation
-
addScope
Adds a new scope to the cache.- Parameters:
scope
- the name of the scopemaxItemsInMemory
- the maximum number of items in memory, before they are evicted- Throws:
InternalCacheEngineException
- if an error occurred in the underlying cache implementation
-
removeScope
Removes an existing scope and all the items that are in it.- Parameters:
scope
- scope to remove- Throws:
InvalidScopeException
- if the specified scope isn't a registered oneInternalCacheEngineException
- if an error occurred in the underlying cache implementation
-
getSize
Returns the quantity of items present in the specified scope.- Returns:
- the size of the scope (quantity of items)
- Throws:
InvalidScopeException
- if the specified scope isn't a registered oneInternalCacheEngineException
- if an error occurred in the underlying cache implementation
-
getKeys
Returns a list of the keys of the items present in the specified scope.- Returns:
- a list of the keys of the available items in the scope
- Throws:
InvalidScopeException
- if the specified scope isn't a registered oneInternalCacheEngineException
- if an error occurred in the underlying cache implementation
-
hasKey
Returns true if there's and item with the specified key in the specified scope.- Returns:
- true if the key exists in the scope, false otherwise
- Throws:
InvalidScopeException
- if the specified scope isn't a registered oneInternalCacheEngineException
- if an error occurred in the underlying cache implementation
-
get
Retrieves an item from a scope.- 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:
InvalidScopeException
- if the specified scope isn't a registered oneInternalCacheEngineException
- if an error occurred in the underlying cache implementation
-
put
void put(String scope, Object key, Object value) throws InvalidScopeException, InternalCacheEngineException Puts an item in a scope.- Parameters:
scope
- scope to add the item tokey
- unique key for the item within this scopevalue
- value to store in the cache- Throws:
InvalidScopeException
- if the specified scope isn't a registered oneInternalCacheEngineException
- if an error occurred in the underlying cache implementation
-
put
void put(String scope, Object key, Object value, long expireAfter, long refreshFrequency, CacheLoader loader, Object... loaderParams) throws InvalidScopeException, InternalCacheEngineException Puts and item in a scope.- Parameters:
scope
- scope to add the item tokey
- unique key for the item within this scopevalue
- value to store in the cacheexpireAfter
- the amount of time (in ticks, where the tick time span is defined at runtime) before the item can be removed from cache. UseCacheItem.NEVER_EXPIRE
to indicate that there's no expiration time.refreshFrequency
- the amount of time (in ticks, where the tick time span is defined at runtime) before items are reloaded into the cache. UseCacheItem.NEVER_REFRESH
to indicate that there's no need for the item to be refreshed. Note that when refreshing, there's almost always an old value for the item in the cache before the new value is loaded into the cache. Theloader
param is also required in order for the item to be refreshed.loader
- the cache loader used to load a new value when the item needs to be refreshed. If not specified and therefreshFrequency
is notCacheItem.NEVER_REFRESH
, the cache will use a default one.loaderParams
- additional parameters the loader could need- Throws:
InvalidScopeException
- if the specified scope isn't a registered oneInternalCacheEngineException
- if an error occurred in the underlying cache implementation
-
remove
Removes an item from a scope.- 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:
InvalidScopeException
- if the specified scope isn't a registered oneInternalCacheEngineException
- if an error occurred in the underlying cache implementation
-
clearAll
Clears the contents of the entire cache.- Throws:
InternalCacheEngineException
- if an error occurred in the underlying cache implementation
-
clearScope
Clears the contents of the specified scope in the cache.- Parameters:
scope
- scope to clear- Throws:
InvalidScopeException
- if the specified scope isn't a registered oneInternalCacheEngineException
- if an error occurred in the underlying cache implementation
-
getStatistics
Returns the statistics of the specified scope in the cache.- Parameters:
scope
- scope to inspect- Returns:
- the statistics
-