Packagecom.whirled.contrib.cache
Classpublic class LFUWeightedAgeCache
ImplementsCache

There are a variety of Least Frequently Used replacement policies used. A strict LFU policy keeps a request count over all time, and replaces the entries with the lowest count. Using that policy, the cache becomes polluted with items that were accessed frequently a long time ago but haven't been accessed recently. An LFU-Aging cache periodically removes counted requests that are too old. This still requires some careful tuning because you have to decide how old "too old" is in your application. This cache builds on LFU-Aging by weighting each access request in favor keeping entries with recent requests. The defaults for this cache dictate that requests that are older than 60 seconds are discarded, and when more than 5 requests have been recorded in the last 60 seconds, only the most recent 5 are used in the cache expiration evaluation. 3 requests recorded 5 seconds ago are worth much more than 3 requests recorded 58 seconds ago.



Public Properties
 PropertyDefined by
  cacheStats : CacheStats
[read-only]
LFUWeightedAgeCache
Protected Properties
 PropertyDefined by
  _cacheValues : Map
LFUWeightedAgeCache
  _evaluator : CacheObjectEvaluator
LFUWeightedAgeCache
  _frequencyCount : int
LFUWeightedAgeCache
  _frequencyThreshold : int
LFUWeightedAgeCache
  _lastEvaluationTotal : int
LFUWeightedAgeCache
  _maxValue : int
LFUWeightedAgeCache
  _missSource : DataSource
LFUWeightedAgeCache
  _stats : CacheStats
LFUWeightedAgeCache
  _timer : Timer
LFUWeightedAgeCache
Public Methods
 MethodDefined by
  
LFUWeightedAgeCache(cacheMissSource:DataSource, maxValue:int = 1000, evaluator:CacheObjectEvaluator = null, evaluationTime:int = 1000, frequencyThreshold:int = 60000, frequencyCount:int = 5)
LFUWeightedAgeCache
  
getObject(name:String):Object
LFUWeightedAgeCache
Protected Methods
 MethodDefined by
  
evaluateCache(... ignored):void
LFUWeightedAgeCache
Property detail
cacheStatsproperty
cacheStats:CacheStats  [read-only]Implementation
    public function get cacheStats():CacheStats
_cacheValuesproperty 
protected var _cacheValues:Map
_evaluatorproperty 
protected var _evaluator:CacheObjectEvaluator
_frequencyCountproperty 
protected var _frequencyCount:int
_frequencyThresholdproperty 
protected var _frequencyThreshold:int
_lastEvaluationTotalproperty 
protected var _lastEvaluationTotal:int
_maxValueproperty 
protected var _maxValue:int
_missSourceproperty 
protected var _missSource:DataSource
_statsproperty 
protected var _stats:CacheStats
_timerproperty 
protected var _timer:Timer
Constructor detail
LFUWeightedAgeCache()constructor
public function LFUWeightedAgeCache(cacheMissSource:DataSource, maxValue:int = 1000, evaluator:CacheObjectEvaluator = null, evaluationTime:int = 1000, frequencyThreshold:int = 60000, frequencyCount:int = 5)

Parameters
cacheMissSource:DataSource — When the data is not found in the cache, it will be requested from this DataSource.
 
maxValue:int (default = 1000) — This maximum value of the objects in the cache. If this value is exceeded, the least frequently used entries are purged.
 
evaluator:CacheObjectEvaluator (default = null) — If no evaluator is provided, an ObjectCountEvaluator will be used, causing this cache to store maxValue objects before it starts to purge unused entries.
 
evaluationTime:int (default = 1000) — The minimum amount of time that must pass between cache evaluations in milliseconds.
 
frequencyThreshold:int (default = 60000) — Any accesses older than this amount will not be considered in the frequency calculation.
 
frequencyCount:int (default = 5) — Only the last frequencyCount accesses will be considered for the frequency calculation.
Method detail
evaluateCache()method
protected function evaluateCache(... ignored):voidParameters
... ignored
getObject()method 
public function getObject(name:String):ObjectParameters
name:String

Returns
Object