CacheBox - Sharing cache across applications

For reasons I won’t get in, I’m working on an application that has two distinct applications, but share common code.

I want to share cache between the two applications. I thought I could do this by specifying “server” as the scope in the “Scope Registeration”, but this doesn’t seem to work. Right now the cache is set for the CFProvider.

Is there any way to make the cache pool available to other applications?

Thanks!

ScopeRegistration only controls where the cache factory object is stored. The storage mechanism of the actual cache providers is another thing.

The CFProvider uses the inbuilt cacheget() and cachePut() functions that the CF engine provides. As far as I know, they are specific to an application and there’s no way to change that.

There are several ways to share caches. Switch to another provider such as the CacheBox provider which allows you to choose a store:

  • JDBC store
  • Disk store
  • Concurrent hashmap memory store
  • etc
    The first 2 are clearly out-of-process, and therefore shared. The hashmap store is in-process, but is contained within the store CFC, so IN THEORY registering CacheBox in the server scope would actually share it. That’s a bit of hack though since CacheBox probably shouldn’t be in your application.

In addition to the CacheBox provider and its many stores, there are other providers such as out Couchbase provider that would let you scale your cache out on a cluster of Couchbase nodes:

http://wiki.coldbox.org/wiki/CacheBox-Couchbase.cfm

Also, have you seen our Quick Reference card on CacheBox?

https://github.com/ColdBox/cbox-refcards/raw/master/CacheBox/CacheBox-Refcard.pdf

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Brad,

Thanks for the reply. I’ve already played around with using the ColdBox provider with different stores (Concurrent, ConcurrentSoftReferenceStore). That works, provided I make sure that my code using the CacheBox instance specified in the Server scope.

The problem is this application is already using ehCache in replication mode on a cluster in production. We’re trying to implement the caching of a lot of high volume objects, to reduce overhead, and I need to sync across the cluster and ideally across the two applications.

I could use the event listeners and try to announce changes across the applications, but I’m really trying to avoid that.

These servers are dedicated servers, running a dedicated application. I may need to play around with using the server scope to allow some kind of cross-application communication, but that’s not very elegant.

Any other thoughts on how I might be able to use ehCache to share the same cache pool across applications?

-Dan

Are you using Lucee? If so, install the EHCache extension, and switch your object cache in the admin to use that named cache. Then point the CF provider to use that cache name.

If you’re using Adobe CF, then you’re at their mercy as to how they name their EHCache regions for each app. If they don’t allow you to override that, then you can’t use the cachePut()/cacheGet() functions or any CacheBox provider that uses them.

However, there is still hope. If you’re on Adobe CF AND need to control the region names in your external EHCache (and you really, really don’t want to switch to Couchbase, because seriously-- it’s freaking amazing) then I would recommend writing up an EHCache provider for CacheBox based on the Java SDK. All you need to do is create a CFC that implements the cachebox.system.cache.ICacheProvider interface.
https://github.com/ColdBox/coldbox-platform/blob/master/system/cache/ICacheProvider.cfc

You can get away with leaving the implementation of many of these methods out based on what parts of the API you’re using. Obvious methods you’d want to implement:

  • get()
  • lookup()
  • set()
  • clear()

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Brad,

Glad to hear that works. I saw the region parameter but I assumed it was just added to the app identifier.

You can put in tickets for CacheBox here:
https://ortussolutions.atlassian.net/projects/CACHEBOX/summary

And you can submit pull requests here:
https://github.com/ColdBox/coldbox-platform/tree/development/system/cache

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Brad,

The reason the “cacheName” ends up being required, is by default CF uses a region name that’s made up of the Application’s name–which is why the cache wasn’t sharing. By specifying a specific cache name, everything is using the same cache pool in ehCache.

I just sent my pull request, so hopefully they’re thought of as useful.

Here’s a summary of the changes:

CFProvider

When a “cacheName” is specified, the configure() method now automatically registers the region in CF10+. Prior to CF9, you didn’t need to create the region ahead of time to use it and I thought it made sense that CacheBox would automatically manage registering a region.

I also fixed an issue in getCachedObjectMetadata(), where there was no logic in place for when you had specified a cacheName. The current code just returns null instead of the metadata for the object.