views:

204

answers:

1

SELECT a.* b.* c.* FROM TOPIC a, BOARD b, MSGS c WHERE c.MessageID = 1 AND a.TopicID = c.MessageID AND b.BoardID = c.BoardID

How to memcache this data? - set_cache("MY_WACKY_QUERY_1", data) note: 1 is the message id

Now there are lots of places in the code which update these 3 tables (independantly of each other), so we need to del_cache("XXX_1") whenever any of these updates and inserts affect MSGS, TOPIC, or BOARD data for, or relating to, the message with id 1

Is there an easy solution? I'm stumped... Any ideas?

A: 

You can't delete data from memcached without knowing the exact cache key that was used to store it. There is no "index" or "key list" from which you can search for stored data.

One solution might be to make your cache lifetimes short enough so that stale data is mostly a non-concern.

Or maybe... I think I'm confused. To me, it kinda looks like you can do this.

<?php

$memcache = new Memcache;
$memcache->connect( 'memcache_host', 11211 );

// do select query here, store into $result

$memcache->set( 'MY_QUERY_1', $result, false, 600 );

// do another select query here, store into $result

$memcache->set( 'MY_QUERY_2', $result, false, 600 );

// Query here updates record with id of 1

$memcache->delete( 'MY_QUERY_1' );
Peter Bailey
First of all thank you very much Peter, for your quick reply.At present i am using 'tangent UDF' MemCache MySql trigger, it is working fine for me to update upto only one table with it's insersion key.can we use trigger for multi table updates, based on MySql Join query ?