Hi! Shouldn't "NewsBlock.AllParams" be just "AllParams"?
I've tried that as well, with the same result. I think you can use both variants.
Ok. Hmm, I'm curious, could you try to add a HiddenField control with the same value as your AllParams property in the user control markup and set an ID on it and use that ID in the varyByControls parameter? :)
Sorry for my late reply. I tried out your suggestion. Unfortunatly, it did not help. The first cached version of block is still showing up on other pages using the same block type.
I am facing a similar problem with MVC shared blocks. Although I am using MVC OutputCache with VaryByParam and not PartialCaching, I (almost) solved my problem by overriding the ToString() function in my BlockData Object. Maybe you could try the same for your NewsBlock controller, in the ToString function I would then return the result you got in AllParams.
Thank you. I tried your approach, unfortunately with the same result as before.
However, I figured out that this issue is limited to similar type blocks on the same page type.
In my case this means that blocks cached on my StartPageType will only occur on that page type. But the same cached blocks (of the same type) will not show on my SectionPageType. But the 1st cached block cached on a page of type SectionPageType will be shared given that both the current page and block is of the same type as cached, regardless of what I've specified in VaryByControl.
As a side note I'll mention that I've also tested this in a vanilla Alloy site, with the same issues.
Here's an update for future reference.
I ended up caching the actual data to be used in my newslists instead of using output cache. Initially I experienced small improvements by using this approach, but after some tweaking I'm pretty satisfied with the result.
We use quite a lot of blocks spread across our site.
These blocks are basically outputting title, image and link based on the child nodes of a pagereference property set in the block's properties.
I'd like to cache each instance of these blocks, and have been playing around with the asp.net outputcache (I've also tried caching just the data, e.g. the pagecollection fetched from a block's pagereference property, but the performance gain was a lot smaller compared to caching the entire usercontrol).
Since a block type may be used on multiple pages and also multiple times on the same page, I figured VaryByControl was the best suited OutputCacheParameters to use. That way, I were hoping that a cached version of the block based on its block properties would be created.
So I did like this:
And in my SiteBlockControlBase base class, I invalidate the cache when content has been changed on the site (via DataFactoryCache.VersionKey):
My problem is - that sporadically, a block cached for one page, may show up on another page (where the same block type, but not instance, is used). So it seems like the block properties are being ignored, and the cached version of the block/usercontrol are served regardless.
I'm questioning if maybe there is some EPiServer "magic" happening behind the scenes that is does not support caching of blocks? Maybe outputcaching of blocks is not supported for this kind of use-case?
Any suggestions are appreciated!