July 12, 2018
Distributed caching in ColdFusion (2018 release)
Comments
(3)
July 12, 2018
Distributed caching in ColdFusion (2018 release)
Newbie 12 posts
Followers: 0 people
(3)

Introduction to new caching engines

ColdFusion already has support for caching using ehcache. There are many caching engines available in the market and each has its pros and cons. Depending upon your application, one caching engine might suit your application more than another. So we need to integrate more caching engines.

In the 2018 release of ColdFusion, we have added support for 3 new caching engines

  • JCS (Java caching system)
  • Redis
  • Memcached

Java Caching System (JCS)

Pros

  • One of the fastest caching solution. It is faster than ehcache.
  • Support for database backup (not related to cfquery).
  • Support for regions and statistics.

Cons

  • Cache replication is difficult.
  • Distributed caching is not possible.

Memcached

Pros

  • Distributed caching and cache replication is easier.
  • Cache memory can reside on a different system.
  • Memcached server is multi-threaded. As a result, it can effectively harness multiple cores.
  • For simple key-value pairs, Memcached is more memory efficient than Redis.
  • Memcached can easily handle websites with high traffic.
  • memcached consumes fewer memory resources for metadata.

Cons

  • Memcached is slower than same VM in-memory caching solutions like ehcache and JCS.
  • You cannot list all keys in Memcached
  • The size of a key cannot be greater than 250 bytes.
  • There is no support for idle time, regions, and statistics (we have written a wrapper).

Redis (REmote DIctionary Server)

Pros

  • Distributed caching and cache replication is easier
  • Cache memory can reside on different systems.
  • Cache persistence is possible.
  • Supports many datatypes – Strings, Hashes, Lists, Sets, etc.

Cons

  • Slower than same VM in-memory caching solutions like ehcache, JCS.
  • Redis is single threaded. As a result, Redis can’t effectively harness multiple cores.
  • There is no support for idle time, regions, and statistics (we have written a wrapper).

Server-side caching engine

Let’s try running this simple caching code, cacheEngines. It inserts an element into the cache, retrieves it, and prints the current caching engine being used.

Cachegetengineproperties is a newly added function which will return the caching engine currently being used by the page. Running this code will print ehcache.

Now let’s go to CF admin and switch the caching engine.

Caching engines

Click on JCS and submit and rerun the downloaded code snippet. It will print JCS this time. So this is how simple it is to switch caching engine at the server level.

Server level caching settings

You can specify server level cache settings for each caching engine from admin in caching page or directly change at lib/rediscache.properties, lib/memcachedcache.properties, lib/cache.ccf, and lib/ehcache.xml.

  • Max idle is the default value for max idle time for any element in cache in seconds.
  • Max life is the default value for the max life span of any element in cache in seconds
  • Max elements is the default value for max number of elements which can be stored in the cache

If eternal is true, elements will not expire ever.

Server levvel properties

Application level caching engines

Users can specify different cache engine at application level in application.cfc. We have introduced a new property this.cache.engine which can accept one of the four values –  ehcache, jcs, redis, memcached. Here you can specify the name of the caching engine which needs to be used for the given application.

Options

We can run the same code present inside some application. It will print the name of the caching engine which you would have specified in application.cfc. So, you can have multiple applications, each using different caching engine which itself would be different from the default caching engine specified at the server level. If no caching engine is provided at application.cfc level, it will pick the default server cache engine.

Application level caching settings

Application level caching settings

In application.cfc file, you can specify the settings for the caching engine specific to this application. Either you can specify the path of property file that will contain key-value pairs of these settings or you  can directly specify them in the form of a struct

You can have two applications, both using Memcached, one with timeToLive value as 60 seconds and another with the value 120 seconds.

Configuring Memcached

While ehcache and JCS come bundled with ColdFusion, Memcached and Redis need to be installed separately. Once you install Memcached, integrating it with ColdFusion is pretty simple. A new section has been added to the caching page – Memcached cache settings. Here you can specify the IP address and port of the Memcached server you have just installed.

Memcached settings

Replication

Multiple ColdFusion nodes can point to same Memcached server.

Distributed caching

If you want distributed caching, you can install multiple Memcached servers and then add comma separated IP addresses of Memcached servers in this section. So if one of the Memcached server goes down, others will take the load and keep on serving.

Configuring Redis

Similar to Memcached, Redis also needs to be installed separately. Once you install it, you need to add the server details in the caching page.

Redis settings

Replication

Multiple ColdFusion nodes can point to same Redis server.

Distributed caching

If you want distributed caching, enable Redis in cluster mode. Once you do that, you need to enable the ‘is cluster’ check-box.

Comparison of engines

Comparison

3 Comments
2019-02-23 20:37:02
2019-02-23 20:37:02

To folks reading this post, it seems worth noting that the new Distributed Caching options in CF2018 (Redis and memcached) are in fact offered only in the Enterprise (and trial and developer) edition only, and NOT in Standard.

Can someone from Adobe confirm? I’m pretty sure I did, when I was helping someone whose site was running CF2018 Standard. While it DID offer the new JCS option (in the CF Admin caching page), it did NOT offer the UI elements for Redis or memcached.

If this is so, then it seems this page (and others) ought to indicate that for readers. From what I’ve seen, there’s a mishmash of indications across various docs (perhaps reflecting a time when edition differences were not known or were not yet stated publicly). Now several months later, they ought to be updated.

First, the  buying guide PDF (alone, currently) DOES indicate currently that “Distributed cache” is Enterprise-only, showing a “New” indication under only the CF2018 Enterprise column and NOT the CF2018 Standard column.

But then the CF features page for Standard DOES list distributed caching, as if it IS a feature of that edition (of course, so does the Enterprise version of that page, as it should).

And this blog post is not the only page that make no mention of edition differences regarding caching. First, the doc page point to in the comments above currently does not, nor does this page also called “buying guide” (despite the name, it’s NOT just an HTML version of the PDF listed above).

Finally, again in making any such changes, it would be important to clarify that (as I understand it) the JCS feature IS in Standard (while new, it’s not technically “distributed”).

As always, hope that helps.

Like
()
2018-10-26 16:39:26
2018-10-26 16:39:26

This is a good article. Will this be added into the documentation for cacheing?

Like
()
(1)
>
James Mohler
's comment
2018-10-29 13:52:25
2018-10-29 13:52:25
>
James Mohler
's comment

James,

We already have, https://helpx.adobe.com/in/coldfusion/developing-applications/changes-in-coldfusion/caching-enhancements.html.

However, I’ll update this page with some new info from the blog.

Like
()
Add Comment