Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is memcached all about timing?

I beleive the standard way to cache something with mamcached is to insert the object into the cache for a set period of time e.g.

 memcli:set(key, rows_array, 5 * 60)

Is there not a better way to cache things where the cache will check inside the database to see if the data has changed rather than relying on a timer which could cause sync issues?

I'm going to use PHP.

like image 274
elfintar Avatar asked Dec 24 '10 21:12

elfintar


2 Answers

The cache will not check the database, because that is contrary to the idea of caching.
Instead you could either update or remove objects from the cache when you change their value in the database.

like image 185
DanJ Avatar answered Sep 18 '22 12:09

DanJ


If data is subject to be modified in the database, not controlled by your application where you can implement your cache in write-through fashion, then that data is probably not a good candidate for caching (assuming you can live with the stale data until it is evicted).

like image 28
Cort Avatar answered Sep 18 '22 12:09

Cort