ColdBox Platform Version 2.6.4

coldbox.system.cache
Class CacheManager

WEB-INF.cftags.component
        extended by coldbox.system.cache.CacheManager
Direct Known Subclasses:
MTCacheManager

public class CacheManager
extends WEB-INF.cftags.component

Manages handler,plugin,custom plugin and object caching. It is thread safe and implements locking for you.


Constructor Summary
init(any controller)
          Constructor
 
Method Summary
private boolean ThresholdChecks()
          JVM Threshold checks
private void announceExpiration(string objectKey)
          Announce an Expiration
 void clear()
          Clears the entire object cache and recreates the object pool and statistics
 void clearAllEvents()
          Clears all events from the cache
 void clearAllViews()
          Clears all views from the cache
 void clearByKeySnippet(string keySnippet, [boolean regex='false'])
          Clears keys using the passed in object key snippet
 void clearEvent(string eventsnippet, [string queryString=''])
          Clears all the event permutations from the cache according to snippet and querystring
 void clearEventMulti(string eventsnippets, [string queryString=''])
          Clears all the event permutations from the cache according to the list of snippets and querystrings
 boolean clearKey(string objectKey)
          Clears an object from the cache by using its cache key
 struct clearKeyMulti(string keys, [string prefix=''])
          Clears objects from the cache by using its cache key
 void clearView(string viewSnippet)
          Clears all view name permutations from the cache according to the view name
 void configure(CacheConfig cacheConfig)
          Configures the cache for operation, sets the configuration object, sets and creates the eviction policy and clears the stats
 void expireAll()
          Expire All Objects
 void expireByKeySnippet(string keySnippet, [boolean regex='false'])
          Same as expireKey but can touch multiple objects depending on the keysnippet that is sent in
 void expireKey(string objectKey)
          Expire an Object
 any get(any objectKey)
          Get an object from cache
 CacheConfig getCacheConfig()
          Get the current cache configuration bean
 CacheStats getCacheStats()
          Return the cache stats object
 struct getCachedObjectMetadata(any objectKey)
          Get the cached object's metadata structure
 struct getCachedObjectMetadataMulti(string keys, [string prefix=''])
          Get the cached object's metadata structure
 struct getItemTypes()
          Get the item types of the cache
 any getJavaRuntime()
          Get the java runtime object for reporting purposes
 struct getMulti(string keys, [string prefix=''])
          The returned value is a structure of name-value pairs of all the keys that where found
 any getObjectPool()
          Get the internal object pool: coldbox
 string getPoolKeys()
          Get a listing of all the keys of the objects in the cache pool
 struct getPoolMetadata([boolean deepCopy='true'])
          Get a copy of the pool's metadata structure
 numeric getSize()
          Get the cache's size in items
private Util getUtil()
          Create and return a util object
 EventURLFacade geteventURLFacade()
          Get the event url facade object
private void initPool()
          Initialize and set the internal object Pool
 boolean lookup(any objectKey)
          Check if an object is in cache, if not found it records a miss
 struct lookupMulti(string keys, [string prefix=''])
          The returned value is a structure of name-value pairs of all the keys that where found or not
 void reap()
          Reap the cache
 boolean set(any objectKey, any myObject, [any timeout=''], [any lastAccessTimeout=''])
          sets an object in cache
 void setCacheConfig(CacheConfig CacheConfig)
          Set & Override the cache configuration bean
 void setEvictionPolicy(AbstractEvictionPolicy evictionPolicy)
          You can now override the set eviction policy by programmatically sending it in
 void setMulti(struct mapping, [any Timeout=''], [any LastAccessTimeout=''], [string prefix=''])
          Sets Multiple Ojects in the cache
 
Methods inherited from class WEB-INF.cftags.component
 

Constructor Detail

init

public init(any controller)
Constructor

Parameters:
controller
Method Detail

ThresholdChecks

private boolean ThresholdChecks()
JVM Threshold checks


announceExpiration

private void announceExpiration(string objectKey)
Announce an Expiration

Parameters:
objectKey - The object key to announce expiration

clear

public void clear()
Clears the entire object cache and recreates the object pool and statistics. Call from a non-cached object or you will get 500 NULL errors, VERY VERY BAD!!. TRY NOT TO USE THIS METHOD


clearAllEvents

public void clearAllEvents()
Clears all events from the cache.


clearAllViews

public void clearAllViews()
Clears all views from the cache.


clearByKeySnippet

public void clearByKeySnippet(string keySnippet, [boolean regex='false'])
Clears keys using the passed in object key snippet

Parameters:
keySnippet - the cache key snippet to use
regex - Use regex or not

clearEvent

public void clearEvent(string eventsnippet, [string queryString=''])
Clears all the event permutations from the cache according to snippet and querystring. Be careful when using incomplete event name with query strings as partial event names are not guaranteed to match with query string permutations

Parameters:
eventsnippet - The event snippet to clear on. Can be partial or full
queryString - If passed in, it will create a unique hash out of it. For purging purposes

clearEventMulti

public void clearEventMulti(string eventsnippets, [string queryString=''])
Clears all the event permutations from the cache according to the list of snippets and querystrings. Be careful when using incomplete event name with query strings as partial event names are not guaranteed to match with query string permutations

Parameters:
eventsnippets - The comma-delimmitted list event snippet to clear on. Can be partial or full
queryString - The comma-delimmitted list of queryStrings passed in. If passed in, it will create a unique hash out of it. For purging purposes. If passed in the list length must be equal to the list length of the event snippets passed in.

clearKey

public boolean clearKey(string objectKey)
Clears an object from the cache by using its cache key. Returns false if object was not removed or did not exist anymore

Parameters:
objectKey - The key the object was stored under.

clearKeyMulti

public struct clearKeyMulti(string keys, [string prefix=''])
Clears objects from the cache by using its cache key. The returned value is a structure of name-value pairs of all the keys that where removed from the operation.

Parameters:
keys - The comma-delimmitted list of keys to remove.
prefix - A prefix to prepend to the keys

clearView

public void clearView(string viewSnippet)
Clears all view name permutations from the cache according to the view name.

Parameters:
viewSnippet - The view name snippet to purge from the cache

configure

public void configure(CacheConfig cacheConfig)
Configures the cache for operation, sets the configuration object, sets and creates the eviction policy and clears the stats. If this method is not called, the cache is useless.

Parameters:
cacheConfig - The configuration object

expireAll

public void expireAll()
Expire All Objects. Use this instead of clear() from within handlers or any cached object, this sets the metadata for the objects to expire in the next request. Note that this is not an inmmediate expiration. Clear should only be used from outside a cached object


expireByKeySnippet

public void expireByKeySnippet(string keySnippet, [boolean regex='false'])
Same as expireKey but can touch multiple objects depending on the keysnippet that is sent in.

Parameters:
keySnippet - The key snippet to use
regex - Use regex or not

expireKey

public void expireKey(string objectKey)
Expire an Object. Use this instead of clearKey() from within handlers or any cached object, this sets the metadata for the objects to expire in the next request. Note that this is not an inmmediate expiration. Clear should only be used from outside a cached object

Parameters:
objectKey

get

public any get(any objectKey)
Get an object from cache. If it doesn't exist it returns the THIS.NOT_FOUND value

Parameters:
objectKey - The key of the object to lookup.

getCacheConfig

public CacheConfig getCacheConfig()
Get the current cache configuration bean.


getCacheStats

public CacheStats getCacheStats()
Return the cache stats object.


getCachedObjectMetadata

public struct getCachedObjectMetadata(any objectKey)
Get the cached object's metadata structure. If the object does not exist, it returns an empty structure.

Parameters:
objectKey - The key of the object to lookup its metadata

getCachedObjectMetadataMulti

public struct getCachedObjectMetadataMulti(string keys, [string prefix=''])
Get the cached object's metadata structure. If the object does not exist, it returns an empty structure.

Parameters:
keys - The comma delimited list of keys to retrieve from the cache.
prefix - A prefix to prepend to the keys

getItemTypes

public struct getItemTypes()
Get the item types of the cache. These are calculated according to internal coldbox entry prefixes


getJavaRuntime

public any getJavaRuntime()
Get the java runtime object for reporting purposes.


getMulti

public struct getMulti(string keys, [string prefix=''])
The returned value is a structure of name-value pairs of all the keys that where found. Not found values will not be returned

Parameters:
keys - The comma delimited list of keys to retrieve from the cache.
prefix - A prefix to prepend to the keys

getObjectPool

public any getObjectPool()
Get the internal object pool: coldbox.system.cache.objectPool or MTobjectPool


getPoolKeys

public string getPoolKeys()
Get a listing of all the keys of the objects in the cache pool


getPoolMetadata

public struct getPoolMetadata([boolean deepCopy='true'])
Get a copy of the pool's metadata structure

Parameters:
deepCopy - Deep copy of structure or by reference. Default is deep copy

getSize

public numeric getSize()
Get the cache's size in items


getUtil

private Util getUtil()
Create and return a util object


geteventURLFacade

public EventURLFacade geteventURLFacade()
Get the event url facade object.


initPool

private void initPool()
Initialize and set the internal object Pool


lookup

public boolean lookup(any objectKey)
Check if an object is in cache, if not found it records a miss.

Parameters:
objectKey - The key of the object to lookup.

lookupMulti

public struct lookupMulti(string keys, [string prefix=''])
The returned value is a structure of name-value pairs of all the keys that where found or not.

Parameters:
keys - The comma delimited list of keys to lookup in the cache.
prefix - A prefix to prepend to the keys

reap

public void reap()
Reap the cache.


set

public boolean set(any objectKey, any myObject, [any timeout=''], [any lastAccessTimeout=''])
sets an object in cache. Sets might be expensive. If the JVM threshold is used and it has been reached, the object won't be cached. If the pool is at maximum it will expire using its eviction policy and still cache the object. Cleanup will be done later.

Parameters:
objectKey - The object cache key
myObject - The object to cache
timeout - Timeout in minutes. If timeout = 0 then object never times out. If timeout is blank, then timeout will be inherited from framework.
lastAccessTimeout - Last Access Timeout in minutes. If timeout is blank, then timeout will be inherited from framework.

setCacheConfig

public void setCacheConfig(CacheConfig CacheConfig)
Set & Override the cache configuration bean. You can use this to programmatically alter the cache.

Parameters:
CacheConfig

setEvictionPolicy

public void setEvictionPolicy(AbstractEvictionPolicy evictionPolicy)
You can now override the set eviction policy by programmatically sending it in.

Parameters:
evictionPolicy

setMulti

public void setMulti(struct mapping, [any Timeout=''], [any LastAccessTimeout=''], [string prefix=''])
Sets Multiple Ojects in the cache. Sets might be expensive. If the JVM threshold is used and it has been reached, the object won't be cached. If the pool is at maximum it will expire using its eviction policy and still cache the object. Cleanup will be done later.

Parameters:
mapping - The structure of name value pairs to cache
Timeout - Timeout in minutes. If timeout = 0 then object never times out. If timeout is blank, then timeout will be inherited from framework.
LastAccessTimeout - Last Access Timeout in minutes. If timeout is blank, then timeout will be inherited from framework.
prefix - A prefix to prepend to the keys

ColdBox Platform Version 2.6.4