downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

セッションのサポート> <Result コールバック
[edit] Last updated: Fri, 25 May 2012

view this page in

Read-through キャッシュコールバック

Read-through キャッシュコールバックが起動されるのは、 アイテムをサーバーから取得できなかったときです。 このコールバックに渡されるのは Memcached オブジェクト、 要求されたキー、そして値を格納する変数への参照です。 このコールバックの役割は、値を設定して true あるいは false を返すことです。 コールバックが true を返した場合は、 Memcached は設定された値をサーバーに格納して呼び出し元の関数にその値を返します。 このコールバックをサポートしているのは Memcached::get()Memcached::getByKey() のみです。 というのも memcache プロトコルでは、 複数のキーが要求されたときにどのキーが見つからなかったのかを知る方法がないからです。

例1 Read-through コールバックの例

<?php
$m 
= new Memcached();
$m->addServer('localhost'11211);

$profile_info $m->get('user:'.$user_id'user_info_cb');

function 
user_info_cb($memc$key, &$value)
{
    
$user_id substr($key5);
    
/* プロファイル情報を DB から探します */
    /* ... */
    
$value $profile_info;
    return 
true;
}
?>


セッションのサポート> <Result コールバック
[edit] Last updated: Fri, 25 May 2012
 
add a note add a note User Contributed Notes Read-through キャッシュコールバック
chadkouse 27-Dec-2011 01:27
the expiration time set for you if you return true from the callback will be 0 (forever) - so if you want a different expiration time you can do the SET operation inside the callback with your custom expiration time.  just make sure you return FALSE from the callback to prevent the client from automatically setting the value again.
chadkouse 27-Dec-2011 01:24
Or just set the value within the callback with your own custom expiration time and return false.  I think it's cleaner.
oorza2k5 at gmail dot com 20-Mar-2009 05:40
This isn't specified anywhere, so I had a gander at the source...

The expiry on read-through cache set values is set to 0, or forever.  This means if you want your key to implicitly expire, don't use the callback methods, instead check for boolean false as a return and manually set the value, at least for now.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites