I imagine VaryByParam applies to query string parameters. In other words, it would serve the same cache for utbildningar?tag=tag1 and utbildningar?tag=tag2, but it would serve different caches for utbildningar/tag1 and utbildningar/tag2.
If you really want to treat the /tag1 and /tag2 versions the same, you could do VaryByCustom and create special criteria in your GetVaryByCustomString method in your custom UmbracoApplication implementation. See here: https://msdn.microsoft.com/en-us/library/5ecf4420.aspx
By the way, you might also have to capitalize the "none" in VaryByParam = "none" so that it says VaryByParam = "None" (I'm not sure if it's case-sensitive).
I have tried capitalizing the none to None with no success.
I have also tried the following: VaryByParam = "None", VaryByCustom = "eventpicker"
With this in global.asax
public override string GetVaryByCustomString(HttpContext context, string custom)
{
if (custom.InvariantEquals("eventpicker"))
{
return "Version=sameValueAlways";
}
return base.GetVaryByCustomString(context, custom);
}
I have then put a breakpoint on the return statement with Version= and it's hit and works.
However, it's only run after it has already generated a new cache for a new url like utbildningar/tag2. I know this because my call actually takes like 6 seconds. And only after about 6 seconds does it break on that return-statement (if I change the url from utbildningar/tag1 to utbildningar/tag2 for instance). If I just reload the same url it uses the cache.
But this VaryByCustom makes no difference because it's only called after the cache has been generated due to new url.
It seems to be the VaryByCustom is useful only to create more caches, not fewer
By the way, you may want to return something other than "Version=sameValueAlways". Not sure if that naming has special behaviors. Perhaps try returning a simple word, like "Hello".
Another thing to keep in mind is that by default, it should take two hits to a page before ASP.NET (or IIS, I forget which) will decide to actually add it to the cache. I think you can configure the number of requests to a page will trigger the caching (e.g., in case you want to change it to 1 visit).
OutputCache always renders on new url despite VaryByParam = "none"
So I want to use OutputCache on a page which is popular. I have used route hijacking in umbraco and this is what it looks like:
It works great.. except one thing... it always generates a new cache if I change the url.
I have this route (which also works great) but as you can see I can add targetGroupTag in the url and this is my problem.
If I type utbildningar/tag1 or utbildningar/tag2 I want the same cache, but no matter what I do this does not happen.
I imagine
VaryByParam
applies to query string parameters. In other words, it would serve the same cache forutbildningar?tag=tag1
andutbildningar?tag=tag2
, but it would serve different caches forutbildningar/tag1
andutbildningar/tag2
.If you really want to treat the /tag1 and /tag2 versions the same, you could do
VaryByCustom
and create special criteria in yourGetVaryByCustomString
method in your customUmbracoApplication
implementation. See here: https://msdn.microsoft.com/en-us/library/5ecf4420.aspxBy the way, you might also have to capitalize the "none" in
VaryByParam = "none"
so that it saysVaryByParam = "None"
(I'm not sure if it's case-sensitive).I should have said, but
I have tried capitalizing the none to None with no success.
I have also tried the following: VaryByParam = "None", VaryByCustom = "eventpicker"
With this in global.asax
I have then put a breakpoint on the return statement with Version= and it's hit and works.
However, it's only run after it has already generated a new cache for a new url like utbildningar/tag2. I know this because my call actually takes like 6 seconds. And only after about 6 seconds does it break on that return-statement (if I change the url from utbildningar/tag1 to utbildningar/tag2 for instance). If I just reload the same url it uses the cache.
But this VaryByCustom makes no difference because it's only called after the cache has been generated due to new url.
It seems to be the VaryByCustom is useful only to create more caches, not fewer
What kind of controller are you implementing (e.g.,
Controller
,RenderMvcController
,SurfaceController
)?I came across this article, which says Umbraco can interfere with output caching: http://www.wiliam.com.au/wiliam-blog/output-caching-can-improve-the-performance-of-your-website
I'm not sure that applies in your case, but it's probably worth a read just in case.
Also, I think Umbraco has a function,
Html.CachedPartial
, that would allow you to cache a partial view. Maybe that would work for your needs. Here's some info about that: https://our.umbraco.org/documentation/reference/templating/mvc/partial-views#cachingBy the way, you may want to return something other than "Version=sameValueAlways". Not sure if that naming has special behaviors. Perhaps try returning a simple word, like "Hello".
Another thing to keep in mind is that by default, it should take two hits to a page before ASP.NET (or IIS, I forget which) will decide to actually add it to the cache. I think you can configure the number of requests to a page will trigger the caching (e.g., in case you want to change it to 1 visit).
is working on a reply...