欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

利用PHP實現(xiàn)一個緩存類-創(chuàng)新互聯(lián)

這篇文章給大家介紹利用PHP實現(xiàn)一個緩存類,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

新?lián)醩sl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!

使用說明:
1、實例化

$cache = new Cache();
2、設(shè)置緩存時間和緩存目錄
$cache = new Cache(60, '/any_other_path/');
第一個參數(shù)是緩存秒數(shù),第二個參數(shù)是緩存路徑,根據(jù)需要配置。
默認(rèn)情況下,緩存時間是 3600 秒,緩存目錄是 cache/
3、讀取緩存
$value = $cache->get('data_key');
4、寫入緩存
$value = $cache->put('data_key', 'data_value');
完整實例:


$cache = new Cache(); 
 
//從緩存從讀取鍵值 $key 的數(shù)據(jù) 
$values = $cache->get($key); 
 
//如果沒有緩存數(shù)據(jù) 
if ($values == false) { 
//insert code here... 
//寫入鍵值 $key 的數(shù)據(jù) 
$cache->put($key, $values); 
} else { 
//insert code here... 
}

Cache.class.php


<?php 
class Cache { 
private $cache_path;//path for the cache 
private $cache_expire;//seconds that the cache expires 
 
//cache constructor, optional expiring time and cache path 
public function Cache($exp_time=3600,$path="cache/"){ 
$this->cache_expire=$exp_time; 
$this->cache_path=$path; 
} 
 
//returns the filename for the cache 
private function fileName($key){ 
return $this->cache_path.md5($key); 
} 
 
//creates new cache files with the given data, $key== name of the cache, data the info/values to store 
public function put($key, $data){ 
$values = serialize($data); 
$filename = $this->fileName($key); 
$file = fopen($filename, 'w'); 
if ($file){//able to create the file 
fwrite($file, $values); 
fclose($file); 
} 
else return false; 
} 
 
//returns cache for the given key 
public function get($key){ 
$filename = $this->fileName($key); 
if (!file_exists($filename) || !is_readable($filename)){//can't read the cache 
return false; 
} 
if ( time() < (filemtime($filename) + $this->cache_expire) ) {//cache for the key not expired 
$file = fopen($filename, "r");// read data file 
if ($file){//able to open the file 
$data = fread($file, filesize($filename)); 
fclose($file); 
return unserialize($data);//return the values 
} 
else return false; 
} 
else return false;//was expired you need to create new 
} 
} 
?>

關(guān)于利用PHP實現(xiàn)一個緩存類就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

本文題目:利用PHP實現(xiàn)一個緩存類-創(chuàng)新互聯(lián)
本文網(wǎng)址:http://www.aaarwkj.com/article46/cchihg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、企業(yè)網(wǎng)站制作云服務(wù)器、響應(yīng)式網(wǎng)站、外貿(mào)建站、定制開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化
日韩 高清 一区二区| 亚洲欧美中文日韩二区一区| 国产亚洲av看码精品永久| 久久五十路初次拍五十路| 9热在线视频精品这里只有| 男人天堂手机视频在线| 九九久久精品久久久精品| 日韩专区欧美二区国产| 开心五月婷婷六月丁香| 国产999精品在线观看| 欧美亚洲午夜一二综合| 亚洲av日韩综合一区尤物| 91久久精品国产一区| 中文字幕国产精品一二区| 日本黄色小网站在线播放| 成熟人妻中文字幕在线看| 色哟哟在线观看精品一区| 日韩精品在线观看大全套| 欧美亚洲午夜一二综合| 亚洲男人天堂最新地址| 国产做a爰片久久91| 中文字幕久精品视频免费| 亚洲一区二区偷拍精品| 国产精品中文第一字幕| 日韩av在线播放亚洲天堂| 亚洲综合精品久久久一区| 欧美午夜国产在线观看| 美女口爆吞精一区二区| 久久久国产精品视频网站| 日本一区二区日本一区| 午夜看片福利欧美熟女| 日韩精品一区二区三区高清| 国产精品久久午夜伦鲁鲁| 国产一区二区精品日韩| 日韩亚洲在线中文字幕| 在线观看高清免费国产| 国产亚洲一区二区精品| 国产亚洲一区二区三区成人| 国产在线麻豆在拍91精品| 亚洲欧美日韩一区91| 观看亚洲一区二区三区大片|