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
- Access your installation media and navigate to configuration\samples\.
- From this location, copy ehcache_context_image_sample.xml to the WEB-INF/classes configuration folder of your Web application.
- Rename ehcache_context_image_sample.xml to ehcache_context_image.xml.
- Open ehcache_context_image.xml for editing.
- Configure the cache in one of the following ways:
- To configure caching settings for the image cache, modify the contents of the
cacheelement with itsaliasset tocom.sdl.context.image.api.ImageTransformer. - To configure caching settings for the timestamp cache, modify the contents of the
cacheelement with itsaliasset tocom.sdl.context.image.ImageUpdateTimeStamp.
- To configure caching settings for the image cache, modify the contents of the
- Each of these elements has the following child content:
<expiry>child element-
Specify the lifetime of this cache in a
ttlgrandchild element, with aunitattribute indicating the unit of measurement, and the actual number of minutes, seconds etc. as the content of thettlelement. For example, to configure a cache with a lifetime of 60 seconds, add the following within thecacheelement:<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 aunitattribute to specify the unit of measurement:Value for unitValid for <heap>?Valid for <disk>?Description entriesyes no heap entries Byes yes bytes kByes yes kilobytes MByes yes megabytes GByes yes gigabytes TByes yes terabytes PByes yes petabytes The
<disk>element also has apersistentattribute, which makes disk caching persistent if set totrue. If disk caching is made persistent, you also require apersistenceelement as a sibling element of thecacheelement, 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 whateverunitis 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>.
- Save and close ehcache_context_image.xml.
- 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.
- 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 element Description Default if not specified configurationResourceNameThe name of the file that contains caching sessions. ehcache_context_image.xml recheckSourceSet to falseto stop the image transformer cache from checking source images for changes periodically.truecheckPeriodSet 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 falseto disable caching.true - 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> - Save and close cwd_engine_conf.xml.
- Restart the Web application to apply your changes.