| Package: MachII.caching |
| Holds cache stats for a concrete strategy. |
<!--- 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: CacheStats.cfc 1153 2008-11-14 22:10:18Z peterfarrell $ Created version: 1.6.0 Updated version: 1.6.0 Notes: Stats on a particular cache's performance may be tracked by a Mach-II provided CFC that exposes several metrics. One potential use of these metrics is to display them inside a dashboard that can be monitored while the application is running. The metrics tracked by Mach-II are as follows: * Cache hits * Cache misses * Cache active element count * Cache total element count * Cache evictions - number of elements that the cache removed to make room for new elements ---> |
| Method Summary | |
|---|---|
| public CacheStats |
init()
Initializes the stats. |
| public void | decrementActiveElements([numeric amount="1"]) |
| public void | decrementCacheMisses([numeric amount="1"]) |
| public void | decrementTotalElements([numeric amount="1"]) |
| public numeric | getActiveElements() |
| public numeric |
getCacheHitRatio()
Gets the hit ratio (decimal) which is (hits / total accesses) where total accesses is hits + misses. |
| public numeric | getCacheHits() |
| public numeric | getCacheMisses() |
| public numeric | getEvictions() |
| public struct |
getExtraStats()
Gets the extra stats which must be a key of this struct. |
| public date | getStatsActiveSince() |
| public numeric | getTotalElements() |
| public void | incrementActiveElements([numeric amount="1"]) |
| public void |
incrementCacheHits([numeric amount="1"])
Increments the number of hits by the default of 1 or by the amount passed. |
| public void | incrementCacheMisses([numeric amount="1"]) |
| public void | incrementEvictions([numeric amount="1"]) |
| public void | incrementTotalElements([numeric amount="1"]) |
| public void |
reset()
Resets all the standard caching stats. |
| public void | setActiveElements(numeric activeElements) |
| public void | setCacheHits(numeric cacheHits) |
| public void | setCacheMisses(numeric cacheMisses) |
| public void | setEvictions(numeric evictions) |
| public void |
setExtraStat(string statName, any statValue)
Sets an extra stats value by stat name. |
| public void | setStatsActiveSince(date statsActiveSince) |
| public void | setTotalElements(numeric totalElements) |
| Method Detail |
|---|
| decrementActiveElements |
|---|
public void decrementActiveElements( [numeric amount="1"] )
Parameters:
| [numeric amount="1"] |
Code:
<cffunction name="decrementActiveElements" access="public" returntype="void" output="false"> <cfargument name="amount" type="numeric" required="false" default="1" /> <cfset variables.activeElements = variables.activeElements - arguments.amount /> </cffunction>
| decrementCacheMisses |
|---|
public void decrementCacheMisses( [numeric amount="1"] )
Parameters:
| [numeric amount="1"] |
Code:
<cffunction name="decrementCacheMisses" access="public" returntype="void" output="false"> <cfargument name="amount" type="numeric" required="false" default="1" /> <cfset variables.cacheMisses = variables.cacheMisses - arguments.amount /> </cffunction>
| decrementTotalElements |
|---|
public void decrementTotalElements( [numeric amount="1"] )
Parameters:
| [numeric amount="1"] |
Code:
<cffunction name="decrementTotalElements" access="public" returntype="void" output="false"> <cfargument name="amount" type="numeric" required="false" default="1" /> <cfset variables.totalElements = variables.totalElements - arguments.amount /> </cffunction>
| getActiveElements |
|---|
public numeric getActiveElements( )
Parameters:
Code:
<cffunction name="getActiveElements" access="public" returntype="numeric" output="false"> <cfreturn variables.activeElements /> </cffunction>
| getCacheHitRatio |
|---|
public numeric getCacheHitRatio( )
Gets the hit ratio (decimal) which is (hits / total accesses) where total accesses is hits + misses.
Parameters:
Code:
<cffunction name="getCacheHitRatio" access="public" returntype="numeric" output="false" hint="Gets the hit ratio (decimal) which is (hits / total accesses) where total accesses is hits + misses."> <cfset var hits = getCacheHits() /> <cfset var totalAccesses = hits + getCacheMisses() /> <cfif hits AND totalAccesses> <cfreturn hits / totalAccesses /> <cfelse> <cfreturn 0 /> </cfif> </cffunction>
| getCacheHits |
|---|
public numeric getCacheHits( )
Parameters:
Code:
<cffunction name="getCacheHits" access="public" returntype="numeric" output="false"> <cfreturn variables.cacheHits /> </cffunction>
| getCacheMisses |
|---|
public numeric getCacheMisses( )
Parameters:
Code:
<cffunction name="getCacheMisses" access="public" returntype="numeric" output="false"> <cfreturn variables.cacheMisses /> </cffunction>
| getEvictions |
|---|
public numeric getEvictions( )
Parameters:
Code:
<cffunction name="getEvictions" access="public" returntype="numeric" output="false"> <cfreturn variables.evictions /> </cffunction>
| getExtraStats |
|---|
public struct getExtraStats( )
Gets the extra stats which must be a key of this struct.
Parameters:
Code:
<cffunction name="getExtraStats" access="public" returntype="struct" output="false" hint="Gets the extra stats which must be a key of this struct."> <cfreturn variables.extraStats /> </cffunction>
| getStatsActiveSince |
|---|
public date getStatsActiveSince( )
Parameters:
Code:
<cffunction name="getStatsActiveSince" access="public" returntype="date" output="false"> <cfreturn variables.statsActiveSince /> </cffunction>
| getTotalElements |
|---|
public numeric getTotalElements( )
Parameters:
Code:
<cffunction name="getTotalElements" access="public" returntype="numeric" output="false"> <cfreturn variables.totalElements /> </cffunction>
| incrementActiveElements |
|---|
public void incrementActiveElements( [numeric amount="1"] )
Parameters:
| [numeric amount="1"] |
Code:
<cffunction name="incrementActiveElements" access="public" returntype="void" output="false"> <cfargument name="amount" type="numeric" required="false" default="1" /> <cfset variables.activeElements = variables.activeElements + arguments.amount /> </cffunction>
| incrementCacheHits |
|---|
public void incrementCacheHits( [numeric amount="1"] )
Increments the number of hits by the default of 1 or by the amount passed.
Parameters:
| [numeric amount="1"] |
Code:
<cffunction name="incrementCacheHits" access="public" returntype="void" output="false" hint="Increments the number of hits by the default of 1 or by the amount passed."> <cfargument name="amount" type="numeric" required="false" default="1" /> <cfset variables.cacheHits = variables.cacheHits + arguments.amount /> </cffunction>
| incrementCacheMisses |
|---|
public void incrementCacheMisses( [numeric amount="1"] )
Parameters:
| [numeric amount="1"] |
Code:
<cffunction name="incrementCacheMisses" access="public" returntype="void" output="false"> <cfargument name="amount" type="numeric" required="false" default="1" /> <cfset variables.cacheMisses = variables.cacheMisses + arguments.amount /> </cffunction>
| incrementEvictions |
|---|
public void incrementEvictions( [numeric amount="1"] )
Parameters:
| [numeric amount="1"] |
Code:
<cffunction name="incrementEvictions" access="public" returntype="void" output="false"> <cfargument name="amount" type="numeric" required="false" default="1" /> <cfset variables.evictions = variables.evictions + arguments.amount /> </cffunction>
| incrementTotalElements |
|---|
public void incrementTotalElements( [numeric amount="1"] )
Parameters:
| [numeric amount="1"] |
Code:
<cffunction name="incrementTotalElements" access="public" returntype="void" output="false"> <cfargument name="amount" type="numeric" required="false" default="1" /> <cfset variables.totalElements = variables.totalElements + arguments.amount /> </cffunction>
| init |
|---|
public CacheStats init( )
Initializes the stats.
Parameters:
Code:
<cffunction name="init" access="public" returntype="CacheStats" output="false" hint="Initializes the stats."> <cfreturn this /> </cffunction>
| reset |
|---|
public void reset( )
Resets all the standard caching stats.
Parameters:
Code:
<cffunction name="reset" access="public" returntype="void" output="false" hint="Resets all the standard caching stats."> <cfset setCacheHits(0) /> <cfset setCacheMisses(0) /> <cfset setEvictions(0) /> <cfset setTotalElements(0) /> <cfset setActiveElements(0) /> <cfset setStatsActiveSince(Now()) /> </cffunction>
| setActiveElements |
|---|
public void setActiveElements( numeric activeElements )
Parameters:
| numeric activeElements |
Code:
<cffunction name="setActiveElements" access="public" returntype="void" output="false"> <cfargument name="activeElements" type="numeric" required="true" /> <cfset variables.activeElements = arguments.activeElements /> </cffunction>
| setCacheHits |
|---|
public void setCacheHits( numeric cacheHits )
Parameters:
| numeric cacheHits |
Code:
<cffunction name="setCacheHits" access="public" returntype="void" output="false"> <cfargument name="cacheHits" type="numeric" required="true" /> <cfset variables.cacheHits = arguments.cacheHits /> </cffunction>
| setCacheMisses |
|---|
public void setCacheMisses( numeric cacheMisses )
Parameters:
| numeric cacheMisses |
Code:
<cffunction name="setCacheMisses" access="public" returntype="void" output="false"> <cfargument name="cacheMisses" type="numeric" required="true" /> <cfset variables.cacheMisses = arguments.cacheMisses /> </cffunction>
| setEvictions |
|---|
public void setEvictions( numeric evictions )
Parameters:
| numeric evictions |
Code:
<cffunction name="setEvictions" access="public" returntype="void" output="false"> <cfargument name="evictions" type="numeric" required="true" /> <cfset variables.evictions = arguments.evictions /> </cffunction>
| setExtraStat |
|---|
public void setExtraStat( string statName, any statValue )
Sets an extra stats value by stat name.
Parameters:
| string statName |
| any statValue |
Code:
<cffunction name="setExtraStat" access="public" returntype="void" output="false" hint="Sets an extra stats value by stat name."> <cfargument name="statName" type="string" required="true" /> <cfargument name="statValue" type="any" required="true" /> <cfset variables.extraStats[statName] = statValue /> </cffunction>
| setStatsActiveSince |
|---|
public void setStatsActiveSince( date statsActiveSince )
Parameters:
| date statsActiveSince |
Code:
<cffunction name="setStatsActiveSince" access="public" returntype="void" output="false"> <cfargument name="statsActiveSince" type="date" required="true" /> <cfset variables.statsActiveSince = arguments.statsActiveSince /> </cffunction>
| setTotalElements |
|---|
public void setTotalElements( numeric totalElements )
Parameters:
| numeric totalElements |
Code:
<cffunction name="setTotalElements" access="public" returntype="void" output="false"> <cfargument name="totalElements" type="numeric" required="true" /> <cfset variables.totalElements = arguments.totalElements /> </cffunction>