I’m building a webapp wherein a post can have a view count. Each time
/posts/:id route is access, it increments the view field but I want to only increment it when the current session hasn’t visited the
/posts/:id route yet.
I’m thinking of using a in-memory storage with ttl like
Cachex to store somewhat a composite key of
post id and
session id or remote ip . Then in the
/posts/:id controller action, I will check if the composite key already exists in the cache, if it is then it will not increment the view field otherwise increment it.
I would like to ask for your thoughts or any better solution.