Using the cart as a cache dependency

James Mosquito asked on March 8, 2021 18:01

Hi, I have a repository method that returns the pages for all products within the cart. Is it possible to use the cart or one of it's properties e.g. cart.CartItems as a cache dependency for that method?

Thanks, James

Correct Answer

Dmitry Bastron answered on March 8, 2021 18:30

Hi James,

The following cache dependency should work:

ecommerce.shoppingcart|byguid|<shoppingCartGuid>
or
ecommerce.shoppingcart|byid|<shoppingCartId>

Under the hood (if you'd look at decompiled ShoppingCartItemInfo class) Cart and CartItems are set as paren-child relationship with touch cache dependencies to true, meaning when you amend CartItems, Cart cache key will be touched as well.

0 votesVote for this answer Unmark Correct answer

Recent Answers


James Mosquito answered on March 9, 2021 11:55

Perfect thanks Dmitry!

0 votesVote for this answer Mark as a Correct answer

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