Control output cache

BJ Blick asked on September 30, 2015 01:23

Hello,

I have a question specifically about the output caching of Kentico. I understand that the output cache is done per-user and that is working fine. However, I have a sub-section of the website where people will be authenticating using a different external system (out of my control). My approach will be to set another cookie to identify those users.

However, the problem becomes that the cached pages get re-used for these external users because the CMS doesn't "know" about them or my cookie, to the CMS they are the same (unauthenticated) user and it thinks it is safe to re-use the cached content.

So my question is, how can I make the output cache vary per a custom factor, for this example, a cookie?

Recent Answers


David te Kloese answered on September 30, 2015 15:17

Hi,

I'd say use a (partial) cache dependency:

https://docs.kentico.com/display/K8/Setting+cache+dependencies

And make it use autenticated, unautenticated, the external role... or something specific for your need!

Greets,

David

0 votesVote for this answer Mark as a Correct answer

BJ Blick answered on September 30, 2015 15:39 (last edited on September 30, 2015 15:39)

Hi David,

Thanks for your answer. Unfortunately cache dependencies do not address my scenario.

Cache dependencies allow you to control the output cache for content. It is also true, that content is cached per user. This must be the case, since I may be displaying the username or email address (for example) on my page. This is briefly mentioned in the docs and can also be verified by some simple testing.

So, cache dependencies are great if you are working in this "per-user" context. But I need to change that assumption, I need the cache to be maintained not just per user but per custom factor (in my case, a cookie). And all cache dependencies, whatever they are, can then be applied to this context.

So, I'm still looking for help here, as I don't see how this can be done.

Thanks

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on September 30, 2015 15:47 (last edited on December 10, 2019 02:30)

Hi,

Not sure if it works but can't you base your cache key on some value in this coockie?

You can read it using a macro.

{% Cookies["CookieName"] |(identity)GlobalAdministrator%}

David

0 votesVote for this answer Mark as a Correct answer

BJ Blick answered on October 1, 2015 01:35 (last edited on October 1, 2015 01:35)

Interesting, if that is possible, then that should solve the problem. I didn't get the impression from the docs you can set cache dependencies like that but I'll try it. Thanks!

0 votesVote for this answer Mark as a Correct answer

BJ Blick answered on October 1, 2015 04:03 (last edited on October 1, 2015 04:06)

Unfortunately, it doesnt work. It has no effect. The macro to evaluate the cookie just returns a string literal such as XYZ. But XYZ doesn't mean anything as a cache key, nothing ever would call TouchKey on it.

So I'm back to my original dilemma, I'm not trying to control when cached content expires, I'm trying to control who it is cached for - a different question entirely.

I am just going to assume what I am trying to do is impossible and find some other (painful) workaround such as creating dummy CMS users to reflect these external users.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.