User Guide Cancel

Caching enhancements

  1. ColdFusion Developers Guide
  2. Develop ColdFusion applications
    1. Introducing ColdFusion
      1. Introducing ColdFusion
      2. About ColdFusion
      3. About Internet applications and web application servers
      4. About JEE and the ColdFusion architecture
    2. Changes in ColdFusion
      1. Changes in ColdFusion
      2. Replacement of JRun with Tomcat
      3. Security enhancements
      4. ColdFusion WebSocket
      5. Enhanced Java integration
      6. ColdFusion ORM search for indexing and search
      7. Solr enhancements
      8. Scheduler enhancements
      9. Integration with Microsoft Exchange Server 2010
      10. RESTful Web Services in ColdFusion
      11. Lazy loading across client and server in ColdFusion
      12. Web service enhancements
      13. Displaying geolocation
      14. Client-side charting
      15. Caching enhancements
      16. Server update using ColdFusion Administrator
      17. Secure Profile for ColdFusion Administrator
    3. Introduction to application development
      1. Introduction to application development using ColdFusion
      2. Using the Developing ColdFusion Applications guide
      3. About Adobe ColdFusion documentation for Developers
    4. The CFML programming language
      1. The CFML programming language
      2. Elements of CFML
      3. ColdFusion variables
      4. Expressions and number signs
      5. Arrays and structures
      6. Extend ColdFusion pages with CFML scripting
      7. Regular expressions in functions
      8. ColdFusion language enhancements
      9. Built-in functions as first class citizen
      10. Data types- Developing guide
    5. Building blocks of ColdFusion applications
      1. Building blocks of ColdFusion applications
      2. Create ColdFusion elements
      3. Write and call user-defined functions
      4. Build and use ColdFusion Components
      5. Create and use custom CFML tags
      6. Build custom CFXAPI tags
      7. Use the member functions
      8. Object Oriented Programming in ColdFusion
    6. Develop CFML applications
      1. Develop CFML applications
      2. Design and optimize a ColdFusion application
      3. Handle errors
      4. Use persistent data and locking
      5. Use ColdFusion threads
      6. Secure applications
      7. Client-side CFML (for mobile development)
      8. Use the ColdFusion debugger
      9. Debugging and Troubleshooting Applications
      10. Develop globalized applications
      11. REST enhancements in ColdFusion
      12. Authentication through OAuth
      13. Social enhancements
    7. Develop mobile applications
      1. Mobile application development
      2. Build mobile applications
      3. Debug mobile applications
      4. Inspect mobile applications
      5. Package mobile applications
      6. Troubleshoot mobile applications
      7. Device detection
      8. Client-side CFML
      9. Mobile Templates
      10. Code samples to build a mobile application
    8. Access and use data
      1. Access and use data
      2. Introduction to Databases and SQL
      3. Access and retrieve data
      4. Update database
      5. Use Query of Queries
      6. Manage LDAP directories
      7. Solr search support
    9. ColdFusion ORM
      1. ColdFusion ORM
      2. Introducing ColdFusion ORM
      3. ORM architecture
      4. Configure ORM
      5. Define ORM mapping
      6. Work with objects
      7. ORM session management
      8. Transaction and concurrency
      9. Use HQL queries
      10. Autogenerate database schema
      11. Support for multiple data sources for ORM
      12. ColdFusion ORM search
    10. ColdFusion and HTML5
      1. ColdFusion and HTML 5
      2. Use ColdFusion Web Sockets
      3. Media Player enhancements
      4. Client-side charting
      5. Display geolocation data
    11. Flex and AIR integration in ColdFusion
      1. Flex and AIR integration in ColdFusion
      2. Use the Flash Remoting Service
      3. Use Flash Remoting Update
      4. Offline AIR application support
      5. Proxy ActionScript classes for ColdFusion services
      6. Use LiveCycle Data Services ES assembler
      7. Use server-side ActionScript
    12. Request and present information
      1. Request and present information
      2. Retrieve and format data
      3. Build dynamic forms with cfform tags
      4. Validate data
      5. Create forms in Flash
      6. Create skinnable XML forms
      7. Use Ajax data and development features
      8. Use Ajax User Interface components and features
    13. Office file interoperability
      1. Office file interoperability
      2. Using cfdocument
      3. Using cfpresentation
      4. Using cfspreadsheet
      5. Supported Office conversion formats
      6. SharePoint integration
    14. ColdFusion portlets
      1. ColdFusion portlets
      2. Run a ColdFusion portlet on a JBoss portal server
      3. Run a ColdFusion portlet on a WebSphere portal server
      4. Common methods used in portlet.cfc
      5. ColdFusion portlet components
      6. Support for JSR-286
    15. Work with documents, charts, and reports
      1. Work with documents, charts, and reports
      2. Manipulate PDF forms in ColdFusion
      3. Assemble PDF documents
      4. Create and manipulate ColdFusion images
      5. Create charts and graphs
        1. About charts
        2. Creating a basic chart
        3. Charting data
        4. Controlling chart appearance
        5. Creating charts: examples
        6. Administering charts
        7. Writing a chart to a variable
        8. Linking charts to URLs
        9. Charting enhancements
      6. Create reports and documents for printing
      7. Create reports with Report Builder
        1. About Report Builder
        2. Common reporting tasks and techniques
        3. Creating a simple report
        4. Getting started
      8. Create slide presentations
    16. Use web elements and external objects
      1. Use web elements and external objects
      2. Use XML and WDDX
      3. Use web services
      4. Use ColdFusion web services
      5. Integrate JEE and Java elements in CFML applications
      6. Use Microsoft .NET assemblies
      7. Integrate COM and CORBA objects in CFML applications
    17. Use external resources
      1. Send and receive e-mail
      2. Interact with Microsoft Exchange servers
      3. Interact with remote servers
      4. Manage files on the server
      5. Use event gateways
      6. Create custom event gateways
      7. Use the ColdFusion extensions for Eclipse
      8. Use the data services messaging event gateway
      9. Use the data management event gateway
      10. Use the FMS event gateway
      11. Use the instant messaging event gateways
      12. Use the SMS event gateway

In ColdFusion, in addition to the default caching engine, Ehcache, the following caching engines are supported:

Changes in the Administrator settings

In the ColdFusion administrator, you can choose the caching engine by clicking Server Settings > Caching.

Choose cache engine
Choose cache engine

For each option, you must make some configuration changes.

JCS

Java Caching System (JCS) is an open source caching engine released through the Apache Jakarta sub-project. JCS provides in-memory caching and algorithms for selectively removing objects from the cache. It also offers more advanced features, such as, indexed disk caching and support for distributed caches.

To use JCS, choose the option in the ColdFusion administrator, as shown above.

You can also configure JCS at the application level. Use the new application variables to set the cache engine and the caching properties file.

Application.cfc

component{
  this.name = "appSpecificCacheTest";
  this.cache.configfile = "jcsconfig.properties";
      this.cache.engine = 'jcs';
  this.applicationTimeout = createtimespan(0,0,0,5); 
}

For more information on the variables you can define in Application. cfc , see Application.cfc variables.

jcsconfig.properties

maxElementsInMemory=5
eternal=false
timeToIdleSeconds=30
timeToLiveSeconds=5

You can also modify the settings via the Administrator (Server Settings > Caching), as shown below:

JCS properties
JCS properties

To verify the configuration, create a cfm, as shown below:

<cfscript>
 writedump(cacheGetEngineProperties()); // Returns the cache engine properties
 writeoutput(cacheGetEngineProperties().name); // Returns the name of the cache engine
</cfscript>

Auxiliary cache support in JCS

You can use JCS to persist cache into a database, which can be accessed via multiple nodes. From the ColdFusion administrator, add a data source for clustering JCS.

From the ColdFusion Administrator, click Server Settings > Caching. Choose the data source from the drop-down.

JCS auxiliary cache settings
JCS auxiliary cache settings

When you save the changes, a table, JCS_STORE gets created in the selected datasource.

This example uses My SQL as auxiliary cache.

To support auxiliary cache in JCS, edit the file cache.ccf located in <coldfusion_install_dir>/cfusion/lib. Add the following lines:

# MYSQL disk cache used for flight options
jcs.auxiliary.MYSQL=org.apache.commons.jcs.auxiliary.disk.jdbc.JDBCDiskCacheFactory
jcs.auxiliary.MYSQL.attributes=org.apache.commons.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes
jcs.auxiliary.MYSQL.attributes.userName=<user name>
jcs.auxiliary.MYSQL.attributes.password=<password>
# Make sure the datasource is the one in which JCS_STORE is created 
# via the Administrator
jcs.auxiliary.MYSQL.attributes.url=jdbc:mysql://localhost:3306/<datasource>
jcs.auxiliary.MYSQL.attributes.driverClassName=com.mysql.jdbc.Driver
jcs.auxiliary.MYSQL.attributes.tableName=JCS_STORE
jcs.auxiliary.MYSQL.attributes.UseDiskShrinker=false

Also set jcs.default = MYYSQL in cache.ccf.

Restart ColdFusion.

The JDBC disk cache uses a relational database, such as MySQL, as a persistent data store. The cache elements are serialized and written into a BLOB.

Memcached

Memcached is a distributed caching solution for Java enterprise applications. A Memcached server can be shared across multiple ColdFusion instances, or multiple Memcached servers can be configured with a single ColdFusion instance.

To use Memcached, download Memcached, and run the server from the command line using the command:

memcached

The Memcached server, picks up the default port 11211.

In the ColdFusion administrator, specify the Memcached server details in Server Settings > Caching.

Memcached server
Memcached server

You can also configure Memcached at the application level. There are two new application variables that you need to use to declare the caching engine.

  • this.cache.engine: Specify the caching engine to be used. Choose from jcs or memcached or ehcache .
  • this.cache.configFile: Specify the configuration file for memcached . For example, the file can contain key-value pairs of caching properties, as shown below:
maxElementsInMemory=5
eternal=false
timeToIdleSeconds=30
timeToLiveSeconds=5

You can also modify the settings via the Administrator (Server Settings > Caching), as shown below. The interface is similar for other cache engines:

Memcached settings
Memcached settings

// Application.cfc

component{
 this.name='appUsingMemcached';
 this.cache.engine='memcached';
 this.cache.configFile='memcachedconfig.properties';
 this.cache.applicationTimeout=createtimespan(0,0,0,5);
}
// memcachedconfig.properties

maxElementsInMemory=5
eternal=false
timeToIdleSeconds=30
timeToLiveSeconds=10

Redis

Redis is an open source (BSD licensed), in-memory data structure store, used as a database and cache. It supports data structures such as strings, hashes, lists, sets, and so on.

To use Redis, download Redis, and run the server from the command line using the command:

redis-server

The Redis server picks up the default port 6379.

Redis is distributed. In a clustered environment, all nodes can communicate with the same Redis node.

In the ColdFusion administrator, specify the Redis server details in Server Settings > Caching.

Redis settings
Redis settings

You can also configure Redis at the application level. There are two new application variables that you need to use to declare the caching engine.

  • this.cache.engine: Specify the caching engine to be used. Choose from jcs, redis, memcached or ehcache.
  • this.cache.configFile: Specify the configuration file for redis. For example, the file can contain key-value pairs of caching properties, as shown below:
maxElementsInMemory=5
eternal=false
timeToIdleSeconds=30
timeToLiveSeconds=5
<!--- Application.cfc --->

<cfcomponent>
    <cfscript>
        this.name = "appSpecificCacheTest";
        this.cache.configfile = "redisconfig.properties";
        this.cache.engine = "redis";
        this.applicationTimeout = createtimespan(0,0,0,5);
    </cfscript>
</cfcomponent>
// redisconfig.properties

maxElementsInMemory=5
eternal=false
timeToIdleSeconds=30
timeToLiveSeconds=5

Custom cache plugin

Apart from using Memcached, Redis, or JCS, you can implement your custom cache plugin. We have provided an interface (C:\ColdFusion2021\cfusion\wwwroot\CFIDE\cache\ICustomCache.cfc), through which you can implement a custom caching engine.

Place your implementations in the same folder as ICustomCache.cfc.

ColdFusion takes advantage of Infinispan libraries. Download the files from the stable release,

  • infinispan -embedded-query-9.1.3.Final.jar
  • infinispan -embedded-9.1.3.Final.jar

Copy the files in C:\ColdFusion2021\cfusion\lib and restart ColdFusion.

To add a custom plugin:

  1. Create a folder in C:\ColdFusion2021\cfusion\wwwroot\CFIDE\cache. Make sure that the name of the folder is same as the name of the custom plugin.

  2. Create <any CFC name>.cfc that implements ICustomCache.cfc and write the implementations. For example,

    <cfcomponent implements="ICustomCache">
        <cffunction name="put" >
            <cfargument name="obj" type="struct">
                <cfoutput>"inside put"</cfoutput>
                <cfset defaultCache=Application.defaultCacheManager.getcache()>
                <cfset defaultCache.put(obj.id,#obj.value#)>
        </cffunction>
    </cfcomponent>
  3. Create config.xml that contains references to Infinispan libraries.

    <infinispan>
        <cache-container default-cache="local">
            <local-cache name="local"/>
        </cache-container>
    </infinispan>
  4. Create Application.cfc.

    <cfcomponent> 
        <cfset this.name= "xyz"> 
            <cfscript> 
                function onApplicationStart() 
                { 
                    writelog("In onApplicationStart()"); 
                    Application.defaultCacheManager=CreateObject("java","org.infinispan.manager.DefaultCacheManager").init('C:\ColdFusion2021\cfusion\wwwroot\custom_cache\config.xml'); 
                    writelog("In onApplicationStart()"); 
    } 
                    function onApplicationEnd() { 
                    writelog("In onApplicationEnd()"); 
    } 
            </cfscript> 
    </cfcomponent>

Create an app with the following:

// Application.cfc

<cfcomponent>
    <cfscript>
        this.name = "mycache_app";
        this.cache.engine = "mycache";
    </cfscript>
</cfcomponent>

Admin APIs

The following are the Admin APIs related to caching that are a part of the 2018 release of ColdFusion. The APIs are a part of runtime.cfc.

verifyRedisCacheStorageConnection

Description: Verifies connection to the Redis cache storage.

Syntax

void verifyRedisCacheStorageConnection (sessionStorageHost, numeric sessionStoragePort, sessionStoragePassword)

Parameter

Req/Opt

Default

Description

sessionStorageHost

Optional

Any

The hostname for Redis cache storage.

sessionStoragePort

Optional

Numeric

The port number for Redis cache storage.

sessionStoragePassword

Optional

Any

The password for the Redis cache storage.

setServerCachingEngine

Description: Changes the caching engine at the server level.

Syntax

void setServerCachingEngine (required engine)

Parameter

Req/Opt

Default

Description

engine

Required

Any

1.       Ehcache

2.      JCS

3.      Memcached

4.      Redis

setJCSClusterDsnName

Description: Set the data source for JCS cluster.

Syntax

void setJCSClusterDsnName (required dsn, required boolean createTables)

Parameter

Req/Opt

Default

Description

dsn

Required

Any

Name of the data source.

createTables

Required

Any

Whether to create a table.

setCachingRedisServer

Description: Set the caching engine for Redis.

Syntax

void setCachingRedisServer (required host, required port, required password, required boolean cluster)

Parameter

Req/Opt

Default

Description

host

Required

any

Host address of the server.

port

Required

any

Port number of the server.

password

Required

any

Password of the server.

cluster

Required

Boolean

Whether a cluster is enabled in Redis.

getMemcachedServer

Description: Gets the details of the Memcached caching engine.

Syntax

any getMemcachedServer ()

For more information on caching in ColdFusion, see Optimizing ColdFusion applications.

Azure Redis Cache

Azure Cache for Redis provides an in-memory data store based on Redis. The caching performance is enhanced by copying frequently accessed data to a high performant storage. With Azure Cache for Redis, this storage is located in-memory instead of being loaded from disk by a database.

Azure Cache for Redis can be used as the following:

  • Distributed data cache
  • Session store
  • Message broker

Azure Cache for Redis is hosted on Azure, and accessible to any application within or outside of Azure. For more information, see Azure Cache for Redis.

In the Azure portal, create a Redis cache.

In the cache details page, enter the following:

  • Primary key
  • Secondary key
  • Primary connection string
  • Secondary connection string

Use these connection details in the Caching page of the ColdFusion Administrator.

After you click Verify Connection, the caching engine now gets stored in Azure cloud.

AWS ElastiCache

Amazon ElastiCache is a Caching-as-a-Service from Amazon Web Services. AWS manages and scales a distributed in-memory cache environment in the cloud. AWS removes the complexity associated with deploying and managing a distributed cache environment.

For more information, see AWS ElastiCache.

AWS ElastiCache provides the following:

  • Automatic detection and recovery from cache node failures.
  • Automatic failover of a failed primary cluster.
  • Flexible Availability Zone placement of nodes and clusters.

Amazon ElastiCache provides two caching engines, Memcached and Redis. You can move your existing Memcached or Redis caching implementation to Amazon ElastiCache effortlessly. Simply change the Memcached/Redis endpoints in your application.

For AWS, you must create an SSL tunnel to an EC2 instance. It will then redirect your localhost to the caching engine port in AWS.

In the AWS console, for Redis and Memcached, create the cache, and then enter the details in the Caching details page of the ColdFusion Administrator.

 Adobe

Get help faster and easier

New user?