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

Vote:
 

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.

Thanks,

Scott

#143590
Jan 27, 2016 11:34
Vote:
 

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

Use ISynchronizedObjectInstanceCache if choosing this path

#143594
Jan 27, 2016 12:46
Vote:
 

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.

#143596
Jan 27, 2016 12:55
Vote:
 

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();
        }
#143600
Jan 27, 2016 14:00
Vote:
 
#143607
Jan 27, 2016 15:53
Vote:
 
#143608
Jan 27, 2016 15:56
Vote:
 

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

#143610
Edited, Jan 27, 2016 16:05
Vote:
 

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.

#143611
Jan 27, 2016 16:16
Vote:
 

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

#143613
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.