Using Your Own Policy
CacheBox is incredibly flexible and if you would like to create your own eviction policy, you can! Below are a set of easy steps on how to do this:
Create a simple CFC that implements the following class
cachebox.system.cache.policies.IEvictionPolicyor use our convenience abstract class and inherit fromcachebox.system.cache.policies.AbstractEvictionPolicyCreate your own
execute()method that will evict items (We recommend looking at existing policies to get an insight on how to do this)Use the policy instantiation path in your
cacheboxproviderproperties
Sample Policy
/**
* FIFO Eviction Policy Command
*/
component extends="cachebox.system.cache.policies.AbstractEvictionPolicy"{
/**
* Constructor
* @cacheProvider The associated cache provider of type: cachebox.system.cache.ICacheProvider
*/
FIFO function init( required cacheProvider ){
super.init( arguments.cacheProvider );
return this;
}
/**
* Execute the policy
*/
function execute(){
var index = "";
// Get searchable index
try{
index = getAssociatedCache()
.getObjectStore()
.getIndexer()
.getSortedKeys( "hits", "numeric", "asc" );
// process evictions via the abstract class
processEvictions( index );
}
catch(Any e){
getLogger().error("Error sorting via store indexer #e.message# #e.detail# #e.stackTrace#.");
}
}
}Process Evictions:
The below code is the code used to evict objects from cache
Configuration File
That's it folks! Very easily you can create your own eviction policies and use our built in indexers to just sort the elements in whatever way you like. If not, you can always do it yourself :)
Was this helpful?