Cache issues with reading and editing in master data

Hello, I’d like to ask 2 questions about Master Data, but first let me give some context on what I’m doing.
It’s a feature for rating custom pages within VTEX. I’m storing the ratings in Master Data and need to increment/decrement the rating values based on the user’s score from 1–5 stars.

My first question is: is there any native way to increment/decrement integer fields in Master Data? Right now I fetch the data from Master Data, add (+1) to the rating field, and when necessary I also subtract the user’s previous rating value.

This brings me to my problem — I’m really struggling with VTEX’s cache.
Let me give an example to make it clearer:

When user A visits page X, they see these numbers:
Page X:
3 five-star ratings;
2 three-star ratings.

When they submit a 5-star rating, I build the query and get back 4 five-star ratings, but user A still sees 3 ratings. And if user B visits the page, they will also see 3 five-star ratings, and if they submit a rating, due to the cache the query will overwrite user A’s rating and also return 4 five-star ratings.

I’d like to know how I can make the query NEVER return cached data, so that whenever there’s a new rating I always fetch the most up-to-date information from Master Data.

Hey @leonardolima, is this scenario for adding ratings to your products?

If so, and your store uses VTEX IO, I’d recommend using Reviews and Ratings<!-- --> by <!-- -->vtex

This app would get you out of the bind.

Cheers

Hello @cristianhg18, thank you for the reply.

In my case it doesn’t work because this app is only for products — I’m creating one for custom pages that are not related to products.
I managed to solve one of the issues by adding pollInterval: 500 directly to my query, so it will keep checking master data for new updates, but for some reason it didn’t work on all queries. Since the main one worked, it meets my needs.

Best regards.