Sitecore comes with out of the box possibilities to configure media caching.
Have a look at the Sitecore.config:
<!-- MEDIA RESPONSE - CACHEABILITY
The <see cref="HttpCacheability">cacheability</see> to use in media response headers.
Possible values: NoCache, Private, Public, Server, ServerAndNoCache, ServerAndPrivate
Default value: private
-->
<setting name="MediaResponse.Cacheability" value="private"/>
<!-- MEDIA RESPONSE - CacheExtensions
The <see cref="HttpCachePolicy.AppendCacheExtension">cache extension(s)</see> to use in media response headers.
Default value: ""
-->
<setting name="MediaResponse.CacheExtensions" value=""/>
<!-- MEDIA RESPONSE - MAX AGE
The <see cref="HttpCachePolicy.SetMaxAge">max age</see> to use in media response headers.
Set it to "00:00:00" to omit this header.
Default value: 7.00:00:00 (seven days)
-->
<setting name="MediaResponse.MaxAge" value="7.00:00:00"/>
<!-- MEDIA RESPONSE - SLIDING EXPIRATION
The <see cref="HttpCachePolicy.SetSlidingExpiration">sliding expiration</see> to use in media response headers.
Set it to "" to omit this header. To include it, use "true" or "false".
Default value: ""
-->
<setting name="MediaResponse.SlidingExpiration" value=""/>
<!-- MEDIA RESPONSE - VARY HEADER
Specifies the value for the Vary HTTP header to use in media response headers.
Set it to "" to omit this header.
Default value: ""
-->
<setting name="MediaResponse.VaryHeader" value=""/>
These are used in the MediaRequestHandler
. Check the handlers
section of your Web.config file.
<add verb="*" path="sitecore_media.ashx" type="Sitecore.Resources.Media.MediaRequestHandler, Sitecore.Kernel" name="Sitecore.MediaRequestHandler"/>
If you want the static user specific PDF files set up correctly, you would need to:
- Not change the MediaResponse.Cacheability since it is already set to private
- Set the MediaResponse.MaxAge to 00:00:00.
- No-store should also already be present due to the setting
DisableBrowserCaching
.
<!-- DISABLE BROWSER CACHING
If true, all pages will have:
Cache-Control: no-cache, no-store
Pragma: no-cache
in the http header
-->
<setting name="DisableBrowserCaching" value="true"/>
You can modify the MediaRequestHandler
to tailor it more to your needs. For example: only logged in users to a specific domain can download media files.
Read this blog for some more information: http://www.doodle.co.uk/blogs/2015/03/03/restricting-access-to-sitecore-media-items