CacheBox: Enterprise Caching
7.x
7.x
  • Introduction
    • Contributing Guide
    • Release History
      • What's New With 7.2.0
      • What's New With 7.1.0
      • What's New With 7.0.0
    • Upgrading to CacheBox 7
    • About This Book
      • Author
  • Getting Started
    • Overview
    • Installing CacheBox
    • Creating CacheBox
      • Common CacheFactory Methods
      • Cache Cleanup/Reaping
  • Configuration
    • CacheBox Configuration
      • CacheBox DSL
        • Default Cache
      • CacheBox Config Object
      • ColdBox Configuration
  • Usage
    • Cache Providers
      • CF Providers
      • Lucee Providers
      • Mock Provider
      • CacheBox Provider
      • Couchbase Providers
    • CacheBox Object Stores
      • ConcurrentStore
      • ConcurrentSoftReferenceStore
      • DiskStore
      • JDBCStore
      • BlackholeStore
  • Advanced Usage
    • CacheBox Eviction Policies
      • Using Your Own Policy
    • CacheBox Event Model
      • CacheBox Events
      • Provider Events
      • Cache Listeners
    • Cache Reporting
      • Creating Your Own Skins
        • Skin Templates
        • ReportHandler
          • Action Commands
  • For The Geeks
    • Caching Concepts
      • Caching Considerations
      • Cache Loading
      • Definitions
      • Java Soft References
    • Cache Topologies
      • Single Instance/In-Process
      • Single Instance/Out-Process
      • Replicated
      • Distributed
    • CacheBox Architecture
      • CacheFactory
      • CacheBoxConfig
      • EventManager
      • ColdBox
      • LogBox
      • ICacheProvider
      • ICacheStats
      • IObjectStore
      • IEvictionPolicy
      • AbstractEvictionPolicy
      • IColdboxApplicationCache
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
Export as PDF
  1. Getting Started
  2. Creating CacheBox

Common CacheFactory Methods

PreviousCreating CacheBoxNextCache Cleanup/Reaping

Last updated 1 year ago

Was this helpful?

Here is a list of some of the most common methods you can use to interact with CacheBox. For full details, please view the online

  • addCache(any<ICacheProvider> cache)

Register a new instantiated cache with this cache factory

  • addDefaultCache(string name)

Add a default named cache to our registry, create it, config it, register it and return it of type: cachebox

  • clearAll()

Clears all the elements in all the registered caches without de-registrations

  • configure(CacheBoxConfig config)

Configure the cache factory for operation, called by the init()

  • expireAll()

Expires all the elements in all the registered caches without de-registrations

  • getCache(string name)

Get a reference to a registered cache in this factory

  • getDefaultCache()

Get the default cache provider of type cachebox

  • reapAll()

A nice way to call reap on all registered caches

  • removeCache(string name)

Try to remove a named cache from this factory

  • replaceCache(any<ICacheProvider> cache, any<ICacheProvider> decoratedCache)

Replace a registered named cache with a new decorated cache of the same name

  • shutdown()

Recursively sends shutdown commands to all registered caches and cleans up in preparation for shutdown

Common Operation Examples

// Add another default cache type but with the name FunkyCache
funkyCache = cachebox.addDefaultCache("FunkyCache");
// Add some elements to funky Cache
funkyCache.set("Myentry",now(),"20");

// Get a reference to a named cache
cfCache = cacheBox.getCache("CFCache");

// Get a reference to the default named cache
cache = cacheBox.getDefaultCache();

// Remove our funky cache no longer needed
cacheBox.removeCache("FunkyCache");

// Create a new cache a replace a cache, the MyFunkyFunkyCache implements ICacheProvider
newCache = new MyFunkyFunkyCache({maxObjects=200,timeout=30});
// replace the CFCache with this one
cacheBox.replaceCache( "CFCache", newCache );

// Add a new cache to cachebox programmatically
newCache = new MyFunkyFunkyCache("FunkynessCache", {maxObjects=200,timeout=30});
cacheBox.addCache( newCache );

// Send a shutdown command to cachebox
cachebox.shutdown();

Info Remember that some of the CacheBox methods announce events. So please see our event model section to see what kind of events you can listen to when working with CacheBox.

API Docs