Blog

Brad Wood

February 28, 2013

Spread the word


Share your thoughts

 

Every ColdBox install comes with an instance of the CacheBox cache aggregator ready to go.  There are two caches that have to be defined: default, and template.  The former is the default provider used if you don't specify another one.  The latter provider is used internally for cached events and views.  What's cool about CacheBox as a cache aggregator is that you can configure as many named providers as you like to report and tune separate areas of your application.
 
Adding an additional named cache is easy and has virtually no overhead since most providers don't use any memory until you begin populating them with data.  Let's start by taking a look at your cache debug monitor:
http://www.mySite.com?debugMode=1&debugpanel=cache
 
 
 
Now, first off you might be wondering how the default and template cache are defined since you might not have any CacheBox-specific configuration in your app.  Don't worry-- if you don't supply any CacheBox configuration, it defaults to the settings found in /coldbox/system/web/config/CacheBox.cfc.  Once you do begin including config for CacheBox, you'll need to include the default and template caches.  
 
Where you store your CacheBox config is completely configurable, but the two most common places is a "cachebox" struct in your main /config/ColdBox.cfc file, or in a separate file /config/CacheBox.cfc that works just like the main config.  My preference is the separate CacheBox.cfc file for organization.  You can get started by simply making a copy of the default CacheBox.cfc in your app's config directory. 
 
To add additional caches, you just need to add more nested structs to the "cachebox.caches" struct like so (I omitted all the default and template details for brevity):
 
cacheBox = {
    defaultCache = {
    ...
    },
    // Register all the custom named caches you like here
    caches = {
        template = {
        ...
        },
        // My new named cache!
        myCache = {
            provider = "coldbox.system.cache.providers.CacheBoxColdBoxProvider",
            properties = {
                evictionPolicy = "LRU",
                maxObjects = 300,
                objectStore = "ConcurrentSoftReferenceStore"
            }
        }
    }
};
 
Now, reinit your application and refresh the cache debug screen.  Your new cache name should show up in the drop down for you to view the stats and contents of it.
 
Using your new cache is also easy.  In a handler for example, the following code is all that is needed:
var myCache = CacheBox.getCache("myCache");
 
If you want to wire your new cache into a model, the following DSL will also work:
component {
    property name='myCache' inject='cachebox:myCache';
}
 
 
P.S. Don't forget to add a debugPassword setting into your app to ensure that you are the only one who can fool around with your CacheBox debug panel.  The URL only changes slightly when you have password:
http://www.mySite.com?debugMode=1&debugpass=myPass&debugpanel=cache

 

Add Your Comment

Recent Entries

ColdBox 7.2.0 Released

ColdBox 7.2.0 Released

ColdBox, a widely used development platform for ColdFusion (CFML), has unveiled version 7.2. Packed with compelling new features, bug fixes, and enhancements, this release is designed to empower developers by boosting productivity, refining scheduled task capabilities, and enhancing the overall reliability and efficiency of application development. This article will delve into the key highlights of ColdBox 7.2 and elucidate how these advancements can positively impact developers in their daily coding endeavors.

Luis Majano
Luis Majano
November 20, 2023
Into the Box 2023 Series on CFCast

Into the Box 2023 Series on CFCast

Excitement is in the air as we unleash the highly anticipated ITB 2023 series exclusively for our valued CFCast subscribers – and the best part? It's FREE for CFCast members! Now is the perfect time if you haven't joined the CFCast community yet. Plus, we've got an incredible End-of-Year deal that's too good to miss

Maria Jose Herrera
Maria Jose Herrera
November 20, 2023
Ortus Deals are Finally Here!

Ortus Deals are Finally Here!

The much-anticipated Ortus End-of-the-Year Sale has arrived, and it's time to elevate your development experience! Whether you're a seasoned developer, a tech enthusiast, or someone on the lookout for top-notch projects, Ortus has something special in store for you. Brace yourself for incredible discounts across a wide array of products and services, including Ortus annual events, books, cutting-edge services, and more.

Maria Jose Herrera
Maria Jose Herrera
November 15, 2023