Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Block ContentReference in GetVaryByCustomString


Does anyone know how to get the ContentReference of the current block when using OutputCache on a block Controller and VaryByCustom?

Within using this and writing code in the GetVaryByCustomString method HttpContext.Current.Request.RequestContext.GetContentLink(); only returns the page ContentLink.



Jan 27, 2016 11:34

I usually take à shortcut and cache the actual expensive data instead.

Use ISynchronizedObjectInstanceCache if choosing this path

Jan 27, 2016 12:46

Expensive data is already cached to the hills to where it can be, I'm just testing out performance improvements on an already near ready to go live website.

Jan 27, 2016 12:55

Not a direct aswer to your question, but I assume you are trying to outputcache the individual block instances.

I have had good results with using the OutputCache on the BlockController with VaryByParam="currentBlock". Then on the BlockData class override the ToString() function to return a block instance specific string like:

      public override string ToString()
            IContent content = this as IContent;
            IChangeTrackable changetrackable = this as IChangeTrackable;
            //IVersionable version = this as IVersionable;

            if (content != null && changetrackable != null)
                return String.Format("{0}-{1}-{2}", content.ContentGuid, changetrackable.Saved.Ticks, EPiServer.Editor.PageEditing.PageIsInEditMode);

            return base.ToString();
Jan 27, 2016 14:00
Jan 27, 2016 15:53
Jan 27, 2016 15:56

Thanks this seems to do effectivly the job I am after .

Edited, Jan 27, 2016 16:05

One more note, I also use VaryByCustom="language" on the OutputCache attribute to differentiate between the 6 languages my site has. The value for the 'language' I set in a GetVaryByCustomString override in Global.asax.

Jan 27, 2016 16:16

Thanks, that's what I've done before myslef for language. Just getting donut hole caching in EpiServer for the block was annoying. Thanks for the help

Jan 27, 2016 16:22
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.