Memcache でキーを設定できないという問題があります。基本的に、テストページがあります:
$db=new db;
$my_test_cache=$db->query("SELECT `txt` FROM `lang` WHERE `pg`='front' LIMIT 2", 10);
キャッシュ用の db クラス:
class db {
public function query($query, $ttl=30, $cache=true, $compr=false) {
global $memcache;
if ($cache==true) {
$res=$memcache->get(hash('md4', $query));
if ($res!=false) {
echo 'this is cached';
return $res;
}
else {
$res=mysql_query($query);
$memcache->set(hash('md4', $query), $res, $compr, $ttl);
echo 'this is not cached<hr>
Query: ',$query,'<br/>
Md4: ',hash('md4',$query),'<br/>';
var_dump($res);
return $res;
}
}
else return mysql_query($query);
unset($res, $query);
}
}
残念ながら、すべてのリソースが適切に機能しているように見えても、キャッシュするデータは設定されません。AKA マイページの出力:
- これはキャッシュされません クエリ: SELECT * FROM
lang
WHEREpg
='front' LIMIT 2 - Md4: 34aa4e46a15413f5091dac79c9e86306
- type の resource(7) (mysql 結果)
ここで何をすべきか教えてくれる親切な人はいますか?