I want to cache mysql tables (key: id, value: row in serialized bytes) into redis. The cache must support TTL and size limit in bytes for each table.
For example: table user
can use 100MB cache, table device
can use 100MB cache.
I tried to implement TTL and size limit in application layer but there is too much overhead in managing and monitoring key expiration.
Anyone know any idea or open source that has done it?
I can't say about go, but basically Redis has a TTL command that allows you to automatically remove the key-value from the cache. In the easiest form you can:
redis> SET table1:id1 "Hello"
"OK"
redis> EXPIRE table1:id1 10 // remove the line after 10 seconds
(integer) 1
redis> TTL table1:id1 // if you want to query
10