| Package: MachII.caching.strategies |
| A caching strategy. This is abstract and must be extended by a concrete strategy implementation. |
<!--- License: Copyright 2008 GreatBizTools, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Copyright: GreatBizTools, LLC Author: Kurt Wiersma (kurt@mach-ii.com) $Id: AbstractCacheStrategy.cfc 1061 2008-09-15 19:46:01Z peterfarrell $ Created version: 1.6.0 Updated version: 1.6.0 Notes: Caching strategies: * Are not Mach-II framework aware and do not have any access to the Mach-II AppManager or other Mach-II Managers. All configuration data should be passed into the strategy via the parameters. * Are not required to implement all the public methods, however you need to override the abstract methods if you do not want to have errors thrown. * Must make use the the CacheStats if you want caching stats available in the Mach-II dashboard. ---> |
| Method Summary | |
|---|---|
| public AbstractCacheStrategy |
init(struct parameters)
Initializes the caching strategy. Do not override. |
| public void |
configure()
Configures the strategy. Override to provide custom functionality. |
| public void |
flush()
Flushes all elements from the cache. |
| public any |
get(string key)
Gets an element by key from the cache. |
| public CacheStats |
getCacheStats()
Gets the cache stats for this caching strategy. |
| public struct |
getConfigurationData()
Gets pretty configuration data for this caching strategy. Override to provide nicer looking information for Dashboard integration. |
| public Log |
getLog()
Gets the log. |
| public any |
getParameter(string name, [any defaultValue=""])
Gets a configuration parameter value, or a default value if not defined. |
| public string |
getParameterNames()
Returns a comma delimited list of parameter names. |
| public struct |
getParameters()
Gets the full set of configuration parameters for the component. |
| public string |
getStrategyType()
Returns the dot path type of the strategy. Required for Dashboard integration. |
| public string |
getStrategyTypeName()
Returns the type name of the strategy. Required for Dashboard integration. |
| public boolean |
isCacheEnabled()
Provides a boolean suggestion to the *calling code* if caching should be used. This does not explicitly turn caching on/off. |
| public boolean |
isParameterDefined(string name)
Checks to see whether or not a configuration parameter is defined. |
| public boolean |
keyExists(string key)
Checks if an element exists by key in the cache. |
| public void |
put(string key, any data)
Puts an element by key into the cache. |
| public void |
reap()
Reaps 'expired' cache elements. |
| public void |
remove(string key)
Removes a cached element by key. |
| public void |
setCacheEnabled(boolean isCacheEnabled)
Sets the boolean suggestion that isCacheEnabled() returns. |
| public void |
setLog(LogFactory logFactory)
Uses the log factory to create a log. |
| public void |
setParameter(string name, any value)
Sets a configuration parameter. |
| public void |
setParameters(struct parameters)
Sets the full set of configuration parameters for the component. |
| Method Detail |
|---|
| configure |
|---|
public void configure( )
Configures the strategy. Override to provide custom functionality.
Parameters:
Code:
<cffunction name="configure" access="public" returntype="void" output="false" hint="Configures the strategy. Override to provide custom functionality."> </cffunction>
| flush |
|---|
public void flush( )
Flushes all elements from the cache.
Parameters:
Code:
<cffunction name="flush" access="public" returntype="void" output="false" hint="Flushes all elements from the cache."> <cfabort showerror="This method is abstract and must be overrided." /> </cffunction>
| get |
|---|
Gets an element by key from the cache.
Parameters:
| string key |
Code:
<cffunction name="get" access="public" returntype="any" output="false" hint="Gets an element by key from the cache."> <cfargument name="key" type="string" required="true" /> <cfabort showerror="This method is abstract and must be overrided." /> </cffunction>
| getCacheStats |
|---|
public CacheStats getCacheStats( )
Gets the cache stats for this caching strategy.
Parameters:
Code:
<cffunction name="getCacheStats" access="public" returntype="MachII.caching.CacheStats" output="false" hint="Gets the cache stats for this caching strategy."> <cfreturn variables.cacheStats /> </cffunction>
| getConfigurationData |
|---|
public struct getConfigurationData( )
Gets pretty configuration data for this caching strategy. Override to provide nicer looking information for Dashboard integration.
Parameters:
Code:
<cffunction name="getConfigurationData" access="public" returntype="struct" output="false" hint="Gets pretty configuration data for this caching strategy. Override to provide nicer looking information for Dashboard integration."> <cfreturn variables.instance /> </cffunction>
| getLog |
|---|
public Log getLog( )
Gets the log.
Parameters:
Code:
<cffunction name="getLog" access="public" returntype="MachII.logging.Log" output="false" hint="Gets the log."> <cfreturn variables.log /> </cffunction>
| getParameter |
|---|
public any getParameter( string name, [any defaultValue=""] )
Gets a configuration parameter value, or a default value if not defined.
Parameters:
| string name |
| [any defaultValue=""] |
Code:
<cffunction name="getParameter" access="public" returntype="any" output="false" hint="Gets a configuration parameter value, or a default value if not defined."> <cfargument name="name" type="string" required="true" hint="The parameter name." /> <cfargument name="defaultValue" type="any" required="false" default="" hint="The default value to return if the parameter is not defined. Defaults to a blank string." /> <cfif isParameterDefined(arguments.name)> <cfreturn variables.parameters[arguments.name] /> <cfelse> <cfreturn arguments.defaultValue /> </cfif> </cffunction>
| getParameterNames |
|---|
public string getParameterNames( )
Returns a comma delimited list of parameter names.
Parameters:
Code:
<cffunction name="getParameterNames" access="public" returntype="string" output="false" hint="Returns a comma delimited list of parameter names."> <cfreturn StructKeyList(variables.parameters) /> </cffunction>
| getParameters |
|---|
public struct getParameters( )
Gets the full set of configuration parameters for the component.
Parameters:
Code:
<cffunction name="getParameters" access="public" returntype="struct" output="false" hint="Gets the full set of configuration parameters for the component."> <cfreturn variables.parameters /> </cffunction>
| getStrategyType |
|---|
public string getStrategyType( )
Returns the dot path type of the strategy. Required for Dashboard integration.
Parameters:
Code:
<cffunction name="getStrategyType" access="public" returntype="string" output="false" hint="Returns the dot path type of the strategy. Required for Dashboard integration."> <cfreturn GetMetadata(this).name /> </cffunction>
| getStrategyTypeName |
|---|
public string getStrategyTypeName( )
Returns the type name of the strategy. Required for Dashboard integration.
Parameters:
Code:
<cffunction name="getStrategyTypeName" access="public" returntype="string" output="false" hint="Returns the type name of the strategy. Required for Dashboard integration."> <cfreturn variables.instance.strategyTypeName /> </cffunction>
| init |
|---|
public AbstractCacheStrategy init( struct parameters )
Initializes the caching strategy. Do not override.
Parameters:
| struct parameters |
Code:
<cffunction name="init" access="public" returntype="AbstractCacheStrategy" output="false" hint="Initializes the caching strategy. Do not override."> <cfargument name="parameters" type="struct" required="true" /> <cfset setParameters(arguments.parameters) /> <cfreturn this /> </cffunction>
| isCacheEnabled |
|---|
public boolean isCacheEnabled( )
Provides a boolean suggestion to the *calling code* if caching should be used. This does not explicitly turn caching on/off.
Parameters:
Code:
<cffunction name="isCacheEnabled" access="public" returntype="boolean" output="false" hint="Provides a boolean suggestion to the *calling code* if caching should be used. This does not explicitly turn caching on/off."> <cfreturn variables.instance.isCacheEnabled /> </cffunction>
| isParameterDefined |
|---|
public boolean isParameterDefined( string name )
Checks to see whether or not a configuration parameter is defined.
Parameters:
| string name |
Code:
<cffunction name="isParameterDefined" access="public" returntype="boolean" output="false" hint="Checks to see whether or not a configuration parameter is defined."> <cfargument name="name" type="string" required="true" hint="The parameter name." /> <cfreturn StructKeyExists(variables.parameters, arguments.name) /> </cffunction>
| keyExists |
|---|
public boolean keyExists( string key )
Checks if an element exists by key in the cache.
Parameters:
| string key |
Code:
<cffunction name="keyExists" access="public" returntype="boolean" output="false" hint="Checks if an element exists by key in the cache."> <cfargument name="key" type="string" required="true" /> <cfabort showerror="This method is abstract and must be overrided." /> </cffunction>
| put |
|---|
public void put( string key, any data )
Puts an element by key into the cache.
Parameters:
| string key |
| any data |
Code:
<cffunction name="put" access="public" returntype="void" output="false" hint="Puts an element by key into the cache."> <cfargument name="key" type="string" required="true" /> <cfargument name="data" type="any" required="true" /> <cfabort showerror="This method is abstract and must be overrided." /> </cffunction>
| reap |
|---|
public void reap( )
Reaps 'expired' cache elements.
Parameters:
Code:
<cffunction name="reap" access="public" returntype="void" output="false" hint="Reaps 'expired' cache elements."> <cfabort showerror="This method is abstract and must be overrided." /> </cffunction>
| remove |
|---|
public void remove( string key )
Removes a cached element by key.
Parameters:
| string key |
Code:
<cffunction name="remove" access="public" returntype="void" output="false" hint="Removes a cached element by key."> <cfargument name="key" type="string" required="true" /> <cfabort showerror="This method is abstract and must be overrided." /> </cffunction>
| setCacheEnabled |
|---|
public void setCacheEnabled( boolean isCacheEnabled )
Sets the boolean suggestion that isCacheEnabled() returns.
Parameters:
| boolean isCacheEnabled |
Code:
<cffunction name="setCacheEnabled" access="public" returntype="void" output="false" hint="Sets the boolean suggestion that isCacheEnabled() returns."> <cfargument name="isCacheEnabled" type="boolean" required="true" /> <cfset variables.instance.isCacheEnabled = arguments.isCacheEnabled /> </cffunction>
| setLog |
|---|
public void setLog( LogFactory logFactory )
Uses the log factory to create a log.
Parameters:
| LogFactory logFactory |
Code:
<cffunction name="setLog" access="public" returntype="void" output="false" hint="Uses the log factory to create a log."> <cfargument name="logFactory" type="MachII.logging.LogFactory" required="true" /> <cfset variables.log = arguments.logFactory.getLog(getMetadata(this).name) /> </cffunction>
| setParameter |
|---|
public void setParameter( string name, any value )
Sets a configuration parameter.
Parameters:
| string name |
| any value |
Code:
<cffunction name="setParameter" access="public" returntype="void" output="false" hint="Sets a configuration parameter."> <cfargument name="name" type="string" required="true" hint="The parameter name." /> <cfargument name="value" type="any" required="true" hint="The parameter value." /> <cfset variables.parameters[arguments.name] = arguments.value /> </cffunction>
| setParameters |
|---|
public void setParameters( struct parameters )
Sets the full set of configuration parameters for the component.
Parameters:
| struct parameters |
Code:
<cffunction name="setParameters" access="public" returntype="void" output="false" hint="Sets the full set of configuration parameters for the component."> <cfargument name="parameters" type="struct" required="true" /> <cfset var key = "" /> <cfloop collection="#arguments.parameters#" item="key"> <cfset setParameter(key, arguments.parameters[key]) /> </cfloop> </cffunction>