Is IPageDataContextRetriever cached?

Danny Winbourne asked on November 2, 2020 10:22

In a follow up to my earlier question - https://devnet.kentico.com/questions/caching-not-working-as-expected-in-kentico-13

Is IPageDataContextRetriever automatically cached.

In ArticleRepository.cs in the dancing goat example project, the GetCurrent() Method has the below call before using IPageRetriever pageRetriever to return the required Article via cache..

** (added at end - editor removing end of my question otherwise.)

I'm a little confused on this code, in that the first call already gets an Article object (maybe it doesn't return all the custom fields?), and from what I can see, would make a database call. This surely negates the 2nd call that uses cache?

** var page = pageDataContextRetriever.Retrieve

Recent Answers


Sean Wright answered on November 2, 2020 19:44

If you are using this API for live-site retrieval of the current page, then yes, it is cached (for a hardcoded value of 10 minutes).

However, if you are using this API during "Edit" / "Preview" mode requests (when using the Page Builder in the Content Management application), then no, it will retrieve the "latest" page every time.

The example in the Dancing Goat code base is confusing because the data is cached an extra time. I think this is to show how to use the IPageRetriever caching or if you want to set additional cache dependencies / cache times that Xperience might not know about for the given Page.

You do not need to cache the result of IPageDataContextRetriever under normal use-cases.

0 votesVote for this answer Mark as a Correct answer

Danny Winbourne answered on November 2, 2020 20:55

Thanks Sean. That’s great and how I hoped it would work. Is the 10 minutes controllable? I.e. can I set it to be a different value? I thinking not as you said it’s hardcoded..

0 votesVote for this answer Mark as a Correct answer

Sean Wright answered on November 2, 2020 21:34

Danny,

From what I can tell, it's very hardcoded for the time being. However, I could see this becoming a configurable value in the future.

Are you looking to increase or decrease the value?

0 votesVote for this answer Mark as a Correct answer

Danny Winbourne answered on November 2, 2020 22:07

Increase, but I think I’ll wrap in a different cache helper method instead.

Hopefully a configurable value will come in future updates.

0 votesVote for this answer Mark as a Correct answer

Sean Wright answered on November 3, 2020 15:10

Danny,

That would be the same approach I'd take. Though, 10 minutes should be plenty of time for most sites.

This caching API caches the TreeNode with its related Page fields, which isn't a small amount of data... if you have a lot of Pages on your site (and SKU Pages), this could use up a non-trivial amount of memory if cached for long periods of time.

0 votesVote for this answer Mark as a Correct answer

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