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

利用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://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| 青青草av一区二区三区| 成人性生交免大片免费| 色婷婷一区二区三区影片| 97热久久精品中文字幕一区| 91伊人日本在线视频| 浮力草草日韩欧美三级| 久久男女激情免费视频| 国产91人妻精品一区二区三区| 国内精品人妻在线中文字幕| 漂亮人妻被中出中文字幕| 日韩精品国产专区一区| 久久精品一品二品三品| 日本又色又爽又黄的观看| 国产精品成人av在线网站| 午夜性色在线视频福利| 国产黄色免费精品网站| 国产高清自拍视频在线一区| 日本韩国av在线观看| 国产亚洲精品久久综合阿香| 欧洲精品久久久久久| 伊人激情久久综合中文字幕| 亚洲女优中文字幕在线免费| 欧美精品久久91九色| 一区二区三区蜜桃91| va精品人妻一区二区三区| 欧美v日韩v亚洲综合国产高清| 欧美日韩亚洲综合在线| 欧美成人高清在线播放| 欧美三级特黄在线播放| 亚洲夫妻性生活免费视频| 91看看午夜福利视频| 香蕉视频欧美久久精品| 日韩成人免费观看视频| 国产精品xxxx国产精品| 国产女人和拘做受视频| 亚洲国产成人精品女人| 亚洲一区二区三区国色天香| 免费国产网站在线观看不卡| 日韩av亚洲一区二区三区|