日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > php >内容正文

php

PHP Memcached + APC + 文件缓存封装

發(fā)布時(shí)間:2025/3/20 php 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP Memcached + APC + 文件缓存封装 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

使用方法:

Memcached

$cache = new Cache_MemCache();
$cache->addServer('www1');
$cache->addServer('www2',11211,20); // this server has double the memory, and gets double the weight
$cache->addServer('www3',11211);
// Store some data in the cache for 10 minutes
$cache->store('my_key','foobar',600);
// Get it out of the cache again
echo($cache->fetch('my_key'));

文件緩存

$cache = new Cache_File();
$key = 'getUsers:selectAll';
// check if the data is not in the cache already
if (!$data = $cache->fetch($key)) {
// assuming there is a database connection
$result = mysql_query("SELECT * FROM users");
$data = array();
// fetching all the data and putting it in an array
while($row = mysql_fetch_assoc($result)) { $data[] = $row; }
// Storing the data in the cache for 10 minutes
$cache->store($key,$data,600);
}

class_cache3.php

<?php
abstract class Cache_Abstract {
abstract function fetch($key);
abstract function store($key, $data, $ttl);
abstract function delete($key);
}
class Cache_APC extends Cache_Abstract {
function fetch($key) {
return apc_fetch($key);
}
function store($key, $data, $ttl) {
return apc_store($key, $data, $ttl);
}
function delete($key) {
return apc_delete($key);
}
}
class Cache_MemCache extends Cache_Abstract {
public $connection;
function __construct() {
$this->connection = new MemCache;
}
function store($key, $data, $ttl) {
return $this->connection->set($key, $data, 0, $ttl);
}
function fetch($key) {
return $this->connection->get($key);
}
function delete($key) {
return $this->connection->delete($key);
}
function addServer($host, $port = 11211, $weight = 10) {
$this->connection->addServer($host, $port, true, $weight);
}
}
class Cache_File extends Cache_Abstract {
function store($key, $data, $ttl) {
$h = fopen($this->getFileName($key), 'a+');
if (!$h)
throw new Exception('Could not write to cache');
flock($h, LOCK_EX);
fseek($h, 0);
ftruncate($h, 0);
$data = serialize(array(time() + $ttl, $data));
if (fwrite($h, $data) === false) {
throw new Exception('Could not write to cache');
}
fclose($h);
}
function fetch($key) {
$filename = $this->getFileName($key);
if (!file_exists($filename))
return false;
$h = fopen($filename, 'r');
if (!$h)
return false;
flock($h, LOCK_SH);
$data = file_get_contents($filename);
fclose($h);
$data = @ unserialize($data);
if (!$data) {
unlink($filename);
return false;
}
if (time() > $data[0]) {
unlink($filename);
return false;
}
return $data[1];
}
function delete($key) {
$filename = $this->getFileName($key);
if (file_exists($filename)) {
return unlink($filename);
}
else {
return false;
}
}
private function getFileName($key) {
return '/tmp/s_cache' . md5($key);
}
}
?>

轉(zhuǎn)載于:https://www.cnblogs.com/hsapphire/archive/2010/03/18/1689215.html

總結(jié)

以上是生活随笔為你收集整理的PHP Memcached + APC + 文件缓存封装的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日韩在线观看免费高清 | 永久免费国产 | 玉女心经 在线 | 亚洲精品一区二区三区蜜臀 | 欧美激情视频一区二区三区不卡 | 国产欧美又粗又猛又爽 | 国产乡下妇女三片 | 黄色av软件 | 国产91一区 | 亚洲性大片 | 成年人免费看 | 日本高清网色 | 国产一区二区免费视频 | 午夜一区在线观看 | 波多野结衣简介 | www婷婷| 色综合色综合网色综合 | 免费黄色入口 | 欧美精品www | 福利一区二区 | 欧美爽妇| 美女88av| 成人va视频 | 国产女人精品 | 天堂视频免费在线观看 | 日韩精品电影一区 | 青青草超碰在线 | 欧美三级三级三级爽爽爽 | 十八岁世界在线观看高清免费韩剧 | 色综合久久久久久久 | 久久久久久久网 | 美国福利片 | 女人十八岁毛片 | 秋霞影院午夜 | 亚洲区国产区 | 亚洲五月天综合 | 在线看黄色网 | 精品aaa| 天天干夜夜撸 | 天堂网视频 | 污到下面流水的视频 | 国产精品麻豆欧美日韩ww | 亚洲成人乱码 | 青青草国产精品 | 欧美wwwxxxx| 成人一级片 | 国产91免费观看 | 午夜性福利视频 | 欧美午夜精品久久久久久浪潮 | 少妇一级淫免费观看 | 亚洲综合社区 | 总裁边开会边做小娇妻h | 在线看污片 | 波多野结衣电影免费观看 | 国产又大又粗又爽的毛片 | 精品91自产拍在线观看二区 | 女性向小h片资源在线观看 日本天天操 | 一级黄色片片 | 总受合集lunjian双性h | 星铁乱淫h侵犯h文 | aaa黄色| 中文字幕一区二区三三 | 美女被啪啪 | 91拔萝卜视频 | 超碰伦理| 尤物网站在线观看 | 日日摸夜夜添夜夜 | 午夜av剧场| 三级网站在线免费观看 | 日本伦理一区 | 最新中文字幕在线观看 | 国产精品久久伊人 | 亚洲中文字幕无码一区 | 国产蜜臀在线 | 人妻丝袜一区二区三区 | 色插综合| 99爱99| japanese国产在线观看 | 大陆av在线| 九九精品视频在线观看 | 国产强伦人妻毛片 | 亚洲v视频| 97视频网址 | 日韩不卡一二三区 | 亚洲欧美日韩天堂 | 肉色丝袜脚交一区二区 | 岳奶大又白下面又肥又黑水多 | 开心色站| 神马影院午夜伦理片 | av成人在线电影 | 亚洲图片激情小说 | 国产又色又爽又黄 | 中文字幕无线码 | 欧美性受xxxxxx黑人xyx性爽 | 亚洲精品视频一区二区三区 | 欧美一区二区日韩 | 最新日韩av在线 | 欧美99视频 | 日韩人妻精品一区二区三区 |