Redis Cache Provider

Last Updated: Jun 17, 2024
documentation for the dotCMS Content Management System

The Redis cache provider enables dotCMS to be used with Redis, an external cache service. For more information on cache providers in dotCMS, see the Cache Chaining documentation.

What is Redis?

Redis is an open source (BSD licensed), in-memory data structure store, used as database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries.

For more information about Redis, please visit the Redis Official Website.

A Redis cache is included with dotCMS, and may be used to customize the cache configuration. The Java client that dotCMS uses to communicate with Redis is called Lettuce, which provides low-latency, non-blocking IO for serializable values, and high overall performance.

Some benefits of this implementation:

  • The caching server can be scaled independently and at runtime in order to add or remove cache capacity.
  • It removes the dotCMS cache from the Java heap, which lowers the dotCMS memory requirement and may significantly speed up garbage collection.
  • Cache “puts” and “removes” are network-wide.
    • There is no external syncing mechanism that can fail.
  • dotCMS servers can be restarted with their caches fully loaded.
  • Provides a shared cache in cluster environments.
  • Allows you to specify a primary/secondary environment (different servers to read/write the data from/to).
  • Offers a configurable pool of connections to access the Redis server.

Enabling Redis

There are 4 steps to enable Redis in dotCMS:

  1. Add the Redis configuration properties via environment variable.
  2. Edit or add cache chain properties to specify the use of Redis for your cache regions.
  3. Shut down your dotCMS instance.
  4. Start your Redis server(s).
  5. Start dotCMS and verify that the Redis cache is working correctly.

Redis Configuration Properties

There are a number of parameters you can use to configure the bahavior of the Redis cache; they can be edited through the use of environment variables.

PropertyDefault ValueDescription
DOT_REDIS_SERVER_KEY_BATCH_SIZE1000[number of keys to interact with at once?]
DOT_REDIS_SERVER_DEFAULT_TTL-1Sets the default Time To Live for all Redis servers — i.e., how long a given key will persist
DOT_REDIS_LETTUCECLIENT_TIMEOUT_MS3000Sets the client timeout in milliseconds
DOT_REDIS_LETTUCECLIENT_MIN_IDLE_CONNECTIONS2Minimum connections to Redis while idle
DOT_REDIS_LETTUCECLIENT_MAX_IDLE_CONNECTIONS2Maximum connections to Redis while idle
DOT_REDIS_LETTUCECLIENT_MAX_CONNECTIONS5Maximum connections possible to Redis servers
DOT_REDIS_LETTUCECLIENT_URLSNoneSet one or more Redis servers via comma-separated list of addresses.
TOMCAT_REDIS_SESSION_ENABLEDfalseIf the Lettuce Client configuration is not set, but the Tomcat Redis Session Manager plugin is activated and this property is true, dotCMS will create the client based on the existing configuration set in the plugin, as a fallback.

Cache Chain Properties

For dotCMS to use Redis, you must add com.dotcms.cache.lettuce.RedisCache to the cache chain properties for the cache regions where you wish to use Redis. For example, to change the default chain to search the Redis cache instead of the default H2 cache, change the default chain with the following environment variable:

DOT_CACHE_DEFAULT_CHAIN: com.dotmarketing.business.cache.provider.caffeine.CaffeineCache,com.dotcms.cache.lettuce.RedisCache

For more information on how to configure cache regions to use the Redis cache provider, see the Cache Chaining documentation.

On this page

×

We Dig Feedback

Selected excerpt:

×