Configure image caching

Cache enabled by default

When installing ImageVault both user mode cache and kernel mode cache is enabled by default.

Kernel Cache serves the cached response very early in the request-response pipeline. Because of that, it's a very fast cache. User mode Cache is a more versatile cache mechanism than the kernel cache mode. It can cache larger responses and also chunked responses, which kernel cache can not. The user mode cache is slower than the kernel mode cache.

The reason both of these cache mechanisms are enabled by default is that a bug in IIS prevents kernel to be activated when not using Internet Explorer as the client browser. Thus images from ImageVault won't be cached if served to Firefox or Chrome users. The user cache, however, caches image requests regardless of which major browser is used.

Our recommendation is that you keep both cache mechanisms enabled to ensure good performance for your users. If you find that the server is using too much RAM you might need to consider turning one of the cache layers off.

In that case our recommendation is to only use the User cache if the site is public. Is the site internal and your policy states using Internet Explorer you would be better of only enabling the kernel cache.

Duration

Recommended values for the cache duration will vary depending on several factors such as load, number of images, hardware etc. so the values in the examples below are just examples.

Enabling both user mode cache and kernel mode cache (recommended)

In the example below both user mode cache and kernel mode cache is enabled for .jpg, .jpeg, .png and .gif-files for the duration of 10 seconds.

<caching>
  <profiles>
    <clear />
    <add extension=".jpg" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="00:00:10" />
    <add extension=".jpeg" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="00:00:10" />
    <add extension=".png" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="00:00:10" />
    <add extension=".gif" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="00:00:10" />
  </profiles>
</caching>

Enabling only user mode cache

in the example config below we have disabled kernel mode cache on .jpg, .jpeg, .png and .gif-files for the duration of 1 minute:

<caching>
  <profiles>
     <clear />
     <add extension=".jpg" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="00:01:00" />
    <add extension=".jpeg" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="00:01:00" />
    <add extension=".png" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="00:01:00" />
    <add extension=".gif" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="00:01:00" />
  </profiles>
</caching>

Enabling only kernel mode cache

In the example below we have disabled the user mode cache and enabled the kernel mode cache on .jpg, .jpeg, .png and .gif-files for the duration of 30 seconds.

<caching>
  <profiles>
    <clear />
    <add extension=".jpg" policy="DontCache" kernelCachePolicy="CacheForTimePeriod" duration="00:00:30" />
    <add extension=".jpeg" policy="DontCache" kernelCachePolicy="CacheForTimePeriod" duration="00:00:30" />
    <add extension=".png" policy="DontCache" kernelCachePolicy="CacheForTimePeriod" duration="00:00:30" />
    <add extension=".gif" policy="DontCache" kernelCachePolicy="CacheForTimePeriod" duration="00:00:30" />
  </profiles>
</caching>

Further reading

For more information, see the official asp.net documentation regarding caching or the web.config configuration documentation regarding the caching element.

comments powered by Disqus