-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache Can be Polluted by Preview Content #2
Comments
@Nicholas-Westby This is cool! Where is the GetKeyWithBuster method and what does it do? |
@Jeavon Let me see if I can remember. It constructs a key that can be used to store pages by in the cache. If you publish a page, this key changes for the page that was published, so that the next request will have a new key (which will cause the cache to refresh). Basically, I couldn't figure out how to clear the cache, so I just create a new entry in the cache. As far as how it is implemented, I think I stored a dictionary with the key being the page ID and the value being a GUID. I'd update that dictionary on publish operations. And the method GetKeyWithBuster would use the GUID in that dictionary to construct the key. By the way, I mentioned that preview mode can be detected with an Umbraco function. Here that is:
|
That's interesting, I've just done some very similar using a custom attribute, you can see here https://gist.github.com/Jeavon/be9f8ca38cf8996ffede |
That looks neat. So, you decorate your action methods with [ConfigDurationOutputCache] and that bypasses caching during requests that occur while a user is previewing the site? |
Yes exactly |
Was just reviewing the GetVaryByCustomString in the Global: https://github.com/jbreuer/Hybrid-Framework-Best-Practices/blob/master/development/Umbraco.Extensions/Utilities/Global.cs
Doesn't look like it's taking into account that the user may be previewing the site. Doesn't that mean elements that are being previewed (i.e., potentially not yet published) may get cached and viewed by normal site visitors who are not in preview mode?
I ask because I've come across this issue in the past. Below is one way to solve it (though, I think there is a built-in Umbraco function you can use rather than looking at the cookie):
The text was updated successfully, but these errors were encountered: