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

search for in the

セッションのサポート> <Result コールバック
Last updated: Fri, 13 Nov 2009

view this page in

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

Read-through キャッシュコールバックが起動されるのは、 アイテムをサーバから取得できなかったときです。 このコールバックに渡されるのは Memcached オブジェクト、 要求されたキー、そして値を格納する変数への参照です。 このコールバックの役割は、値を設定して true あるいは false を返すことです。 コールバックが true を返した場合は、 Memcached は設定された値をサーバに格納して呼び出し元の関数にその値を返します。 このコールバックをサポートしているのは Memcached::getMemcached::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;
}
?>


add a note add a note User Contributed Notes
Read-through キャッシュコールバック
oorza2k5 at gmail dot com
21-Mar-2009 10: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.

セッションのサポート> <Result コールバック
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites