Provide examples of using CacheBox


I've been reading through the CacheBox and ColdBox documentation for good examples of how to use CacheBox, and I'm coming up a little short. Barely any of the sample ColdBox applications employ caching.

In particular, I'd like to know what best practices are. Do people set a lot of custom caches to keep things organized? How do they usually check that a cached item is expired and then renew it? CacheBox is very flexible, as is CFML, and I just don't want to head down a bad practice road if I don't have to.


Luis Majano
September 21, 2016, 9:06 PM

There are so many topics around caching that it is difficult to translate via one sample app or docs. This is where our online training approach would be able to answer more questions. Also, maybe additions to online presentations. I will add something for ODW this year around caching.

Brad Wood
September 21, 2016, 9:43 PM

If you'd still like some better examples, can you perhaps provide some very specific examples and I can work on creating some samples for those specific use cases.

Regarding your specific questions in the ticket, there are no real best practices around caching per se. You can create as many separate caches as you like. As far as checking for an item, just use the documented API for cache providers. My favorite, which is part of the Coldbox providers, is the getOrSet() method which will always return the cached item, executing a closure if necessary to create it. It's seamless and requires no special locking or race conditions.



Luis Majano


Miles Rausch