# Common CacheFactory Methods

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 [API Docs](http://apidocs.ortussolutions.com/cachebox/current)

* `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

```javascript
// 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cachebox.ortusbooks.com/5.x-1/getting-started/creating-cachebox/common-cachefactory-methods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
