CacheBox Configuration
CacheBox comes pre-configured for operation for caching using a default cache. However, you can customize CacheBox using different strategies by levarging the CacheBox Configuration DSL.
When you are in a ColdBox application, you will have a cachebox structure in your ColdBox.cfc already that you can use, or you can create a portable CFC as well and place it in config/CacheBox.cfc
The cool thing about this CacheBox DSL is that it is the same whether you are using CacheBox in ColdBox applications or any other framework or non-framework ColdFusion application.
Configuration can be done in the following ways:
No configuration: Uses the default configuration shown below
Portable CFC: Creating a portable data CFC using the CacheBox DSL in a
configure()methodProgrammatic Config: Creating the CacheBox
Configobject and interacting with its methods programmaticallyCacheBox DSL Struct: Passing a struct literal into CacheBox, using the CacheBox DSL.
1. Default Configuration
This is the default configuration when CacheBox is created with no config. CacheBox will
Use a default LogBox configuration to the console
Register CacheBox in the CFML
applicationscope ascacheboxCreate a
defaultcacheusingConcurrentSoftReferenceStorestorage
/**
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ----
* The default ColdBox CacheBox configuration object that is used when the cache factory is created by itself
**/
component {
/**
* Configure CacheBox, that's it!
*/
function configure(){
// The CacheBox configuration structure DSL
cacheBox = {
// LogBox Configuration file
logBoxConfig : "coldbox.system.cache.config.LogBox",
// Scope registration, automatically register the cachebox factory instance on any CF scope
// By default it registers itself on server scope
scopeRegistration : {
enabled : true,
scope : "application", // the cf scope you want
key : "cacheBox"
},
// The defaultCache has an implicit name of "default" which is a reserved cache name
// It also has a default provider of cachebox which cannot be changed.
// All timeouts are in minutes
// Please note that each object store could have more configuration properties
defaultCache : {
objectDefaultTimeout : 120,
objectDefaultLastAccessTimeout : 30,
useLastAccessTimeouts : true,
reapFrequency : 2,
freeMemoryPercentageThreshold : 0,
evictionPolicy : "LRU",
evictCount : 1,
maxObjects : 300,
objectStore : "ConcurrentSoftReferenceStore",
// This switches the internal provider from normal cacheBox to coldbox enabled cachebox
coldboxEnabled : false
},
// Register all the custom named caches you like here
caches : {},
// Register all event listeners here, they are created in the specified order
listeners : [
// { class="", name="", properties={} }
]
};
}
}2. Portable CFC
You can create a CFC with a single configure method with the CacheBox configuration in a variable called cachebox using the CacheBox DSL.
3. Programmatic Config
You can create an instance of the cachebox.system.cache.config.CacheBoxConfig and calling methods on it.
4. Struct Literal Config
You can also use a struct literal to configure CacheBox
Last updated
Was this helpful?