memcache - when good to use

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

memcache - when good to use

Post by jmut »

Hi,
I read stuff about memcache at http://www.danga.com/memcached/
and this look really good right...basically if you show some stats or something like stats.php?id=5 you cache this...and all users use the cache at same time...doing sql query once actually...
Only question is how do you tell memcache to update the cache... any tips and tricks on that...are you doing like refresh on each INSERT/UPDATE/DELETE on data that concerns the memcached thing?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

As long as the INSERT/UPDATE/DELETE operation knows about the correct key for the corresponding data in memcache, it can update the data itself.
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

Post by dbevfat »

You can invalidate the cache upon UPDATE/DELETE. Inserting records isn't really a problem, because there is no record in cache to invalidate.

Another way is to have a TTL (time to live) saved with each cache entry and requery the database every once in a while. This means the cache will contain some stale records at a given time but for many cases this isn't really a problem.

regards
Post Reply