| Package: MachII.caching |
| Inherits from: framework.BaseComponent < framework.Property |
| Allows you to configure the Mach-II caching features. |
<!--- License: Copyright 2007 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: CachingProperty.cfc 1088 2008-09-26 00:25:20Z peterfarrell $ Created version: 1.6.0 Updated version: 1.6.0 Notes: Simple configuration that uses the timespan strategy with its' default parameters as the basic strategy: <property name="Caching" type="MachII.caching.CachingProperty"/> This will cache data for a timespan of 1 hour by using the MachII.caching.strategies.TimeSpanCache Example configuration of multiple caching strategires: <property name="Caching" type="MachII.caching.CachingProperty"> <parameters> <!-- Naming a default cache name is not required, but required if you do not want to specify the 'name' attribute in the cache command --> <parameter name="cachingEnabled" value="true" /> <parameter name="defaultCacheName" value="foo" /> <parameter name="foo"> <struct> <key name="type" value="MachII.caching.strategies.TimeSpanCache" /> <key name="scope" value="application" /> <key name="timespan" value="0,1,0,0"/><!-- Cache for 1 hour --> <key name="cleanupIntervalInMinutes" value="3" /> </struct> </parameter> <parameter name="bar"> <struct> <key name="type" value="MachII.caching.strategies.LRUCache" /> <key name="size" value="100" /> <key name="scope" value="application" /> </struct> </parameter> </parameters> </property> See individual caching strategies for more information on configuration. ---> |
| Method Summary | |
|---|---|
| public void |
configure()
Configures the property. |
| private void |
configureStrategy(string name, struct parameters)
Configures a strategy. |
| private string |
createCacheId(string cacheName)
Creates a cache indentifier. |
| public void |
disableCaching()
Disables caching. Same as calling getAppManager().getCacheManager().disableCaching() |
| public void |
enableCaching()
Enables caching. Same as calling getAppManager().getCacheManager().enableCaching() |
| public boolean |
getCachingEnabled()
Gets the value if caching is enabled. |
| public string | getDefaultCacheName() |
| public void |
setCachingEnabled(boolean cachingEnabled)
Sets if caching is enabled. |
| public string | setDefaultCacheName(string defaultCacheName) |
| Methods inherited from framework.Property: init |
|---|
| Methods inherited from framework.BaseComponent: announceEvent , isParameterDefined , bindValue , setParameter , getParameter , buildUrlToModule , getAppManager , getComponentNameForLogging , getLog , getParameterNames , setProperty , hasParameter , getPropertyManager , announceEventInModule , setAppManager , getProperty , getParameters , setLog , setParameters , buildUrl |
|---|
| Method Detail |
|---|
| configure |
|---|
public void configure( )
Configures the property.
Parameters:
Code:
<cffunction name="configure" access="public" returntype="void" output="false"
hint="Configures the property.">
<cfset var cacheStrategyManager = getAppManager().getCacheManager().getCacheStrategyManager() />
<cfset var params = getParameters() />
<cfset var defaultCacheParameters = StructNew() />
<cfset var key = "" />
<cfif isParameterDefined("defaultCacheName")>
<cfset setDefaultCacheName(getParameter("defaultCacheName")) />
</cfif>
<cfloop collection="#params#" item="key">
<cfif IsStruct(params[key])>
<cfset configureStrategy(key, getParameter(key)) />
</cfif>
</cfloop>
<cfif NOT StructCount(cacheStrategyManager.getCacheStrategies())>
<cfset defaultCacheParameters.type = variables.defaultCacheType />
<cfset configureStrategy(variables.defaultCacheName, defaultCacheParameters) />
</cfif>
<cfif NOT Len(getDefaultCacheName()) AND StructCount(cacheStrategyManager.getCacheStrategies()) EQ 1>
<cfset setDefaultCacheName(ListGetAt(StructKeyList(cacheStrategyManager.getCacheStrategies()), 1)) />
</cfif>
<cfset getAppManager().getCacheManager().setDefaultCacheName(getDefaultCacheName()) />
<cfif NOT getParameter("cachingEnabled", true)>
<cfset getAppManager().getCacheManager().disableCaching() />
</cfif>
</cffunction>
| configureStrategy |
|---|
private void configureStrategy( string name, struct parameters )
Configures a strategy.
Parameters:
| string name |
| struct parameters |
Code:
<cffunction name="configureStrategy" access="private" returntype="void" output="false" hint="Configures a strategy."> <cfargument name="name" type="string" required="true" hint="Name of the strategy" /> <cfargument name="parameters" type="struct" required="true" hint="Parameters for this strategy." /> <cfset var key = "" /> <cfif NOT StructKeyExists(arguments.parameters, "type")> <cfthrow type="MachII.caching.MissingCacheStrategyType" message="You must specify a parameter named 'type' for cache named '#arguments.name#' in module named '#getAppManager().getModuleName()#'." /> </cfif> <cfset arguments.parameters.generatedScopeKey = createCacheId(arguments.name) /> <cfloop collection="#arguments.parameters#" item="key"> <cfset arguments.parameters[key] = bindValue(key, arguments.parameters[key]) /> </cfloop> <cfset getAppManager().getCacheManager().getCacheStrategyManager().loadStrategy(arguments.name, arguments.parameters.type, arguments.parameters) /> </cffunction>
| createCacheId |
|---|
private string createCacheId( string cacheName )
Creates a cache indentifier.
Parameters:
| string cacheName |
Code:
<cffunction name="createCacheId" access="private" returntype="string" output="false" hint="Creates a cache indentifier."> <cfargument name="cacheName" type="string" required="true" /> <cfset var moduleName = getAppManager().getModuleName() /> <cfif NOT Len(moduleName)> <cfset moduleName = "_base_" /> </cfif> <cfreturn getAppManager().getAppKey() & "._MachIICaching._" & Hash(moduleName & "_" & arguments.cacheName) /> </cffunction>
| disableCaching |
|---|
public void disableCaching( )
Disables caching. Same as calling getAppManager().getCacheManager().disableCaching()
Parameters:
Code:
<cffunction name="disableCaching" access="public" returntype="void" output="false" hint="Disables caching. Same as calling getAppManager().getCacheManager().disableCaching()"> <cfset getAppManager().getCacheManager().disableCaching() /> </cffunction>
| enableCaching |
|---|
public void enableCaching( )
Enables caching. Same as calling getAppManager().getCacheManager().enableCaching()
Parameters:
Code:
<cffunction name="enableCaching" access="public" returntype="void" output="false" hint="Enables caching. Same as calling getAppManager().getCacheManager().enableCaching()"> <cfset getAppManager().getCacheManager().enableCaching() /> </cffunction>
| getCachingEnabled |
|---|
public boolean getCachingEnabled( )
Gets the value if caching is enabled.
Parameters:
Code:
<cffunction name="getCachingEnabled" access="public" returntype="boolean" output="false" hint="Gets the value if caching is enabled."> <cfreturn variables.cachingEnabled /> </cffunction>
| getDefaultCacheName |
|---|
public string getDefaultCacheName( )
Parameters:
Code:
<cffunction name="getDefaultCacheName" access="public" returntype="string" output="false"> <cfreturn variables.defaultCacheName /> </cffunction>
| setCachingEnabled |
|---|
public void setCachingEnabled( boolean cachingEnabled )
Sets if caching is enabled.
Parameters:
| boolean cachingEnabled |
Code:
<cffunction name="setCachingEnabled" access="public" returntype="void" output="false" hint="Sets if caching is enabled."> <cfargument name="cachingEnabled" type="boolean" required="true" /> <cfset variables.cachingEnabled = arguments.cachingEnabled /> </cffunction>
| setDefaultCacheName |
|---|
public string setDefaultCacheName( string defaultCacheName )
Parameters:
| string defaultCacheName |
Code:
<cffunction name="setDefaultCacheName" access="public" returntype="string" output="false"> <cfargument name="defaultCacheName" type="string" required="true" /> <cfset variables.defaultCacheName = arguments.defaultCacheName /> </cffunction>