Documentation Center

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 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, modify the contents of the cache element with its alias set to com.sdl.context.image.api.ImageTransformer.
    • To configure caching settings for the timestamp cache, modify the contents of the cache element with its alias set to com.sdl.context.image.ImageUpdateTimeStamp.
  6. Each of these elements has the following child content:
    <expiry> child element
    Specify the lifetime of this cache in a ttl grandchild element, with a unit attribute indicating the unit of measurement, and the actual number of minutes, seconds etc. as the content of the ttl element. For example, to configure a cache with a lifetime of 60 seconds, add the following within the cache element:
    <expiry>
      <ttl unit="seconds">60</ttl>
    </expiry>
    <resources> child element

    If you want to use a variety of caching types, use the <resources> child element. Within this <resources> element, you can have the <heap> grandchild element, for on-heap caching, or the <disk> grandchild element, for disk caching.

    Both child elements have a unit attribute to specify the unit of measurement:
    Value for unitValid for <heap>?Valid for <disk>?Description
    entriesyesnoheap entries
    Byesyesbytes
    kByesyeskilobytes
    MByesyesmegabytes
    GByesyesgigabytes
    TByesyesterabytes
    PByesyespetabytes

    The <disk> element also has a persistent attribute, which makes disk caching persistent if set to true. If disk caching is made persistent, you also require a persistence element as a sibling element of the cache element, directly above it. This element is empty, and has one attribute, directory, which must be set to the directory in which you wish to persist your cache.

    Both <heap> and <disk> set the cache size (in number of bytes, kilobytes, or whatever unit is set to) in the element content.

    <heap> child element

    If you intend to use only on-heap caching, you can use the <heap> element, as described above, as a direct child to <cache>, instead of as a grandchild element. That is, you use <heap> instead of <resources>.

  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.