修改FLEA.php的510行开始的getCache,writeCache,purgeCache一共3个函数,使用memcache库。

不过好像这样对于我的wb的优化感觉不大,还是仔细考虑,自己在程序逻辑上查询量大、更新少的需要的地方添加memcache比较重要。话说查询最多的可能就是Tweets了,可是实时变化。。唉。。。

memcached的使用很方便,但是原理很牛逼,推荐看mixi.jp人写的东西

http://tech.idv2.com/2008/07/10/memcached-001/

 function getCache($cacheId, $time = 900, $timeIsLifetime = true, $cacheIdIsFilename = false)
 {
 $memcache_obj = new Memcache;
 $memcache_obj->connect('localhost', 11211);
 $data = $memcache_obj->get($cacheId);
 if(!$data) return false;

 return $data !== false ? unserialize($data) : false;
 }

 function writeCache($cacheId, $data, $cacheIdIsFilename = false)
 {
 $data = serialize($data);

 $memcache_obj = new Memcache;
 $memcache_obj->connect('localhost', 11211);
 return $memcache_obj->set($data, $cacheId, MEMCACHE_COMPRESSED, 900);

 }

 function purgeCache($cacheId, $cacheIdIsFilename = false)
 {
 $memcache_obj = new Memcache;
 $memcache_obj->connect('localhost', 11211);
 return $memcache_obj->delete($cacheId);
 }
转载请注明来源:Leoncom-《为fleaphp添加memcached》
Trackback

4 comments untill now

  1. 杂这火

  2. Your posting is abelsutoly on the point!

  3. Normally I’m against killing but this article slghuatered my ignorance.

  4. That’s an expert answer to an inrtiesteng question

Add your comment now