4

We have a requirement where we don't want to cache certain entities which are retrieving data dynamically from an external system. I was going through the documentation and found below option

  • To suppress caching for an entity, such as one that exists for dynamic data, add the DxaNoCacheOutput attribute to the entity. (check this link)

Therefore, I am not sure how to use this attribute for an entity. Had anyone used this option before? (looking for a sample implementation).

I am using DXA 2.2 with Tridion Sites 9.1

3
  • Disable which cache, output or model? Is the entity obtained dynamically or added to the Page directly?
    – Atila Sos
    Jul 20, 2022 at 22:40
  • Good question, I think Atila is asking to see which configuration option would fit best. The web application caching documentation for .NET mentions caching options for "regions." And there's a separate topic on caching example for "dynamically modified view models". Jul 22, 2022 at 19:06
  • Hi Atila, the entity is added to the page but we are dynamically populating a list and adding it to the entity. The main problem is when I disable RenderOutput in the web.config, it is working fine. I tried to add [DxaNoCacheOutput] attribute for the entity but still no luck. Jul 25, 2022 at 15:22

1 Answer 1

4

Caching in DXA works great for simple use cases but can quickly get very complicated if you have exotic scenarios. I myself have spent a lot of time getting familiar with how it works in detail and trust me, it's a lot of variables :).

The [DxaNoCache] really does nothing on Entity Models if those entities are implicit on a Page. Note that I say implicit and not static (embedded) CPs. A DCP directly added to a Page is also implicit as the Model Service embeds it into the PageModelData, subsequently it ends up in the PageModel having passed through the Model Builder Pipeline.

If you wish to disable the output (rendered) cache for the Entity, you need to use [DxaNoOutputCache] on the Model. Note that this in turn will disable the Page output caching as well. And it should if you think about it.

I could go on but I think this is enough information for your use case :).

2
  • Excellent point that all Component Presentations are embedded into the PageModelData, regardless if they're added to the page in a static or dynamic way. I think "reference" or "referenced by" would be another way to describe what you call "implicit." :-) Jul 27, 2022 at 20:21
  • Thank you very much. I will try that and confirm. Jul 28, 2022 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.