Callbacks
php 手册 | 脚本学堂 | 脚本编程 | 网站编程 | 系统管理 | 服务器配置 | 数据库管理 | Php教程 | python教程 | 正则表达式 | 批处理脚本 | Centos教程 | Linux基础教程

Read-through cache callbacks

Read-through cache callbacks are invoked when an item cannot be retrieved from the server. The callback is passed the Memcached object, the requested key, and the by-reference value variable. The callback is responsible for setting the value and returning true or false. If the callback returns true, Memcached will store the populated value on the server and return it to the original calling function. Only Memcached::get and Memcached::getByKey support these callbacks, because the memcache protocol does not provide information on which keys were not found in the multi-key request.

Example #1 Read-through callback example

<?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);
    
/* lookup profile info in the DB */
    
...
    
$value $profile_info;
    return 
true;
}
?>

Callbacks
php 手册 | 脚本学堂 | 脚本编程 | 网站编程 | 系统管理 | 服务器配置 | 数据库管理 | Php教程 | python教程 | 正则表达式 | 批处理脚本 | Centos教程 | Linux基础教程