Configuring Contextual Image Delivery caching

CID can cache both the images being transformed themselves, and the timestamps for those images. Configure caching to your liking by creating and editing a CID caching configuration file.

Procedure

  1. Access your installation media and navigate to configuration\samples\.
  2. From this location, copy ehcache_context_image_sample.xml to the WEB-INF/classes (Java) or bin\config\ (.NET) configuration folder of your Web application.
  3. Rename ehcache_context_image_sample.xml to ehcache_context_image.xml.
  4. Open ehcache_context_image.xml for editing.
  5. Configure the cache in one of the following ways:
    • To configure caching settings for the image cache, edit the attributes of the cache element with its name set to com.sdl.context.image.api.ImageTransformer.
    • To configure caching settings for the timestamp cache, edit the attributes of the cache element with its name set to com.sdl.context.image.ImageUpdateTimeStamp.
  6. Each of these elements has the following configurable attributes:
    AttributeDescriptionDefault for image cacheDefault for timestamp cache
    eternalSet to true to ignore all timeouts and never expire elements in this cache. If this attribute is set to true, timeToLiveSeconds and timeToIdleSeconds are ignored.falsefalse
    maxBytesLocalDiskThe maximum amount of memory a cache can use in its local disk space. The value is a number followed by a letter indicating the unit of measurement.nonenone
    maxBytesLocalHeapThe maximum amount of memory a cache can use in its local heap memory. The value is a number followed by a letter indicating the unit of measurement. For example, "500k" denotes maxBytesLocalHeap"500 kilobytes", "200m" denotes "200 megabytes", "2g" denotes "2 gigabytes" and "20%" denotes "20 percent of available memory".10%20M
    maxElementsInMemoryThe maximum number of items for this cache that can be in memory. Set to 0 to set no maximum.10001000
    maxEntriesLocalDiskThe maximum number of cache entries a cache can use in its local disk space.nonenone
    maxEntriesLocalHeapThe maximum number of cache entries a cache can use in its local heap memory.10001000
    overflowToDiskSet to true if the disk cache should be used when local memory is used up.falsefalse
    statisticsSet to false if you do not want CID to gather caching statistics and make them available through the API.truetrue
    timeToIdleSecondsThe maximum number of seconds that an element can exist in the cache without being used.12101220
    timeToLiveSecondsThe maximum number of seconds that an element can exist in the cache, regardless of whether it is used or not.24102420
  7. Save and close ehcache_context_image.xml.
  8. Only if you have pressing reasons to change the default caching behavior of CID, in the same location, open the configuration file cwd_engine_conf.xml.
  9. If you want to configure any of the following options, ensure the presence of a <cache> section in this file and configure one or more of the following child elements:
    Child elementDescriptionDefault if not specified
    configurationResourceNameThe name of the file that contains caching sessions.ehcache_context_image.xml
    recheckSourceSet to false to stop the image transformer cache from checking source images for changes periodically.true
    checkPeriodSet to an interval (in milliseconds) at which you want the cache to check for changes in resource images.100000 (that is, every 100 seconds)
    enabledSet to false to disable caching.true
  10. By default, transformed images are written to memory only. If you want to enable the storage of transformed images in a temporary folder (for example, because you expect such images to be so large as to impact performance), ensure the presence of an <image> section in this file and add the following within this section:
    <io>
      <useTempFileCache>true</useTempFileCache>
    </io>
  11. Save and close cwd_engine_conf.xml.
  12. Restart the Web application to apply your changes.