1

I want to use redis as cache for mysql, and the main idea is:

Query

  1. read from redis

  2. if not exist, read from mysql, and add to redis cache

Add

  1. write to mysql directly

Update&Delete

  1. write to mysql
  2. invalidate the cache of redis

My question is: how to invalidate the cache?

I know I can delete it, or set a expire time, is it a usual way, or are there any standard methods to invalidate the cache?

Thanks!

Jimmy Guo
  • 1,288
  • 1
  • 9
  • 24

1 Answers1

2

You would need a trigger to tell redis that mysql data has been updated.

  1. This can be a part of your code, whenever you save data to mysql, you invalidate the redis cache as well.

  2. You can use streams like http://debezium.io/ to capture changes in the database, and take neccessary actions like invalidating cache.

DhruvPathak
  • 42,059
  • 16
  • 116
  • 175