Answer the question
In order to leave comments, you need to log in
How to cache comments correctly?
Tell me how to cache comments correctly?
Now I just cache the data from the database with the latest comments, there is a cache for 5 minutes, but when someone adds a comment, it will not be visible for these 5 minutes until the cache time expires, what to do?
Delete cache after adding comments? But if comments are sent every few seconds, is there any point in this?
Answer the question
In order to leave comments, you need to log in
The moment you write the comment to the database, you read the cache, add the newly received comment to it and remove the oldest one from the stack, overwrite the cache without changing its expiration time.
The approach scales well and does not increase the load on the base.
The only disadvantage of this approach is the difficulty in implementing changes to the cached content.
The second disadvantage is that if a shared cache is not used, but local copies on instances, then cache inconsistency is possible.
The approach may not work if the cache is organized incorrectly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question