3

I'm using the feather package and building feather widgets for Sitefinity 9.1. I can't seem to override the Output Cache for the widgets using the OutputCache attribute: [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]. I don't want to have to disable caching at the page level, just at the widget level. How do I disable caching at the widget level in Sitefinity?

drogon
  • 1,785
  • 3
  • 21
  • 34

1 Answers1

1

Better do it on the client-side, especially given that the Sitefinity's team is doing exactly that in the Login Status feather widget which should not be output cached:

The View contains two divs that are initially hidden and shown via javascript on the client depending on the status of the user (which is retrieved via web service):

https://github.com/Sitefinity/feather-widgets/blob/master/Telerik.Sitefinity.Frontend.Identity/Mvc/Views/LoginStatus/LoginStatus.LoginName.cshtml

The js code:

https://github.com/Sitefinity/feather-widgets/blob/master/Telerik.Sitefinity.Frontend.Identity/Mvc/Scripts/LoginStatus/login-status.js

EDIT: What you can try is to subscribe to the PageManager.Executing event and see if the page that was changed was your parent/group page. If so, then you can get all its child pages (PageData) with the API and increase their BuildStamp property with 1. This will invalidate their cache. More info here: http://docs.sitefinity.com/tutorial-subscribe-to-events-using-dataprovider-or-manager-class

Veselin Vasilev
  • 3,698
  • 1
  • 15
  • 21
  • Unfortunately, client-side is not an option for us, since the widget content needs to be SEO friendly. – drogon Aug 23 '16 at 00:10
  • Maybe if you provide more details it would be easier to find alternatives. For instance what is the nature of the data - is it confidential per user or is it something that just changes frequently, like a share price? Actually both of the above cases are not SEO friendly, so wondering what the details are. – Veselin Vasilev Aug 23 '16 at 03:27
  • It is public facing data --the header and footer for a template. Basically the header and footer can inherit data defined as custom fields in a parent page group/page node. When the data is changed at the parent page, it is not reflected in the child pages, since those child pages are not removed from cache. – drogon Aug 23 '16 at 14:39
  • I assume you are using a custom MVC widget for the header and footer and that widget takes the custom field value from the parent page and does something with it. I updated my answer above – Veselin Vasilev Aug 24 '16 at 01:04
  • that solution seemed to work. However, it would be nice if widgets could just support outputcache attribute. – drogon Aug 25 '16 at 14:58
  • Agree that that would be nice to have. Please mark as answer if it worked for you – Veselin Vasilev Aug 26 '16 at 00:21
  • actually, updating the build stamp for the pages messed up module builder, so I ended up going with some code using CacheDependency and that is working, but your idea of listening for PageManager got me started, thanks! – drogon Aug 26 '16 at 23:21
  • Would like to understand in what way the build stamp messed the module builder. Good that you found a solution though – Veselin Vasilev Aug 27 '16 at 23:50
  • I believe that module builder is creating pages when a new dynamic module is initialized. In this code, it loses a reference to the page because the build stamp has changed. It throws a null reference exception. – drogon Aug 28 '16 at 15:00
  • but you change the build stamp on front end pages only, right, not backend pages? – Veselin Vasilev Aug 29 '16 at 21:37
  • Yes, but it also appears to be creating a front end page for widget display or something in module builder... – drogon Aug 29 '16 at 22:50
  • It creates only a widget for displaying the data on the front-end, but not the page, probably something else was going on there – Veselin Vasilev Aug 30 '16 at 21:55