Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello! Have anyone good practice with static files in Umbraco? Right now I have only two methods.
1) use @Html.ChachedPartial()
2) add in web.config. (here I very much doubt that this is the best method
httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" />
I'll be greateful for any help.
(system.webServer/staticContent/clientCache is for static resources (files))
you can create your own implementation of CachedPartial, something like this:
public static class CachedPartialExtensions
//(From version 7 there is an overload for CachedPartial that allows the key to be passed in)
public static IHtmlString CachedPartial(
this HtmlHelper htmlHelper,
bool cacheByPage = false,
bool cacheByMember = false,
ViewDataDictionary viewData = null,
Func<object, ViewDataDictionary, string> contextualKeyBuilder = null);
var newCacheKey = "fpc-"; //prefix to know which keys to clear on page publish (in Bootstraper.cs file)
newCacheKey += partialViewName;
newCacheKey += "page-" + UmbracoContext.Current.PageId;
newCacheKey += "key-" + cacheKey;
var result = MemoryCache.Default.Get(newCacheKey) as MvcHtmlString;
if(result == null)
result = htmlHelper.Partial(partialViewName, model, viewData);
MemoryCache.Default.Add(new CacheItem(newCacheKey, result), new CacheItemPolicy
AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(cachedSeconds)
The use case for this would be:
contextualKeyBuilder: (model, viewData) =>
return (model as MyViewModel).Id.ToString();
you will be able to provide your own keys for cache:
@Html.MyCachedPartial("PartialView", Model, 60, cacheKey: "model1key", cacheByPage: true)
@Html.MyCachedPartial("PartialView", Model2, 60, cacheKey: "model2key", cacheByPage: true)
Thanks, it looks interesting I will definitely try it. Is it possible to manage all static elements? For example, I want ALL the images(.png or .jpg) on the site to be stored in the cache for 3 days.
Try to use Client side caching
Easy way to add client side caching to site - add this section to your Web.config:
<clientCache cacheControlMode="UseMaxAge" cacheControlCustom="public" cacheControlMaxAge="7.00:00:00" />
(For example, cache-control: max-age=120 means that the returned resource is valid for 120 seconds, after which the browser has to request a newer version)
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted