R
R
root092016-10-02 18:57:09
caching
root09, 2016-10-02 18:57:09

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

2 answer(s)
D
Dmitry Kim, 2016-10-02
@kimono

As an option - triggers or cache tagging.

P
Philipp, 2016-10-02
@zoonman

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 question

Ask a Question

731 491 924 answers to any question