caching with memcache and CDbCacheDependency

Hi, need some help to clarify the concept.


$sql = 'SELECT * FROM tbl_post LIMIT 20';

$dependency = new CDbCacheDependency('SELECT MAX(update_time) FROM tbl_post');

$rows = Yii::app()->db->cache(1000, $dependency)->createCommand($sql)->queryAll();

[list=1]

[*]if the cache contains an entry indexed by the SQL statement.

[*]if the dependency has not changed (the maximum update_time value is the same as when the query result was saved in the cache).

[/list]

I do not understand what do the above explanation means. Especially second one with regards to maximum update_time. Please correct me if I am wrong.

There is a update_time column in tbl_post table. Whenever a row is updated, the update_time is updated too. If a post is retrieved from the cache, CDbCacheDependency will first query the database for MAX(update_time)? What is the purpose of this and how exactly does it works in keeping the cache updated?

Another question is regarding memcache. Not sure if it is appropriate to ask here. I understand that it is possible to cluster memcache servers. Say I have the below configurations.

1 memcache server in US. 1 memcache server in Europe.

My Yii website makes use of the cluster of 2 nodes. memcache will split the caching between the 2 nodes.

[list=1]

[*]user A retrieves a post from database and cached it. assume (123,$model) in US node.

[*]user B wants to retrieve the same post, from Europe. Will looking for key 123 finds the cache? Does it matters if both users are in US or Europe?

[/list]

Thanks!!

Try this




$sql = 'SELECT * FROM tbl_post LIMIT 20';


$dependency = new CDbCacheDependency('SELECT MAX(update_time) FROM tbl_post');


$post = new Post();

$post = $post->cache(1000,$dependency);


// NOW QUERY FOR RESULT LIKE


$post = $post->findAll();

/* OR */

$post->dbConnection->createCommand($sql);

/* OR */

$post->findAllBySql($sql);




Pardon my ignorance, but you are trying to show me that during creation of new post, it will be cached. What will subsequent calls to findAll posts do?

But I still do not understand the concepts I asked previously.