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

利用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)化
亚洲精品欧美激情专区| 成人一区二区三区乱码| 国产成人亚洲欧美激情| 国产一区二区精品久久久女同| 九色国产一区二区三区| 97精品久久九九中文字幕| 在线观看91高清视频| 一卡二卡三卡四卡日韩| 饥渴少妇高潮特殊按摩| 亚洲综合av婷婷激情| 白小白的视频在线观看| 久久热这里只有精品网站| 一区二区三区乱码av| 不卡一区二区福利日本| 啪啪视频日韩一区二区| 欧美曰韩国内精品中文| 日本高清不卡在线播放| 国产av无毛一区二区三区| 亚洲男人天堂av电影| 日本高清不卡在线一区二区| 日韩欧美黄片一区二区三区| 精品国产一区二区三区四不卡在线| 不卡av免费在线网址| 91欧美激情另类亚洲| 97资源视频在线播放| 亚洲精品在线观看日本| 亚洲精品国产精品乱码不卞 | 一区二区久久精品视频| 国产九色91中文在线视频| 色婷婷久久五月中文字幕| 精品亚洲av一区二区三区| 久久精品国产亚洲av超一| 91精品国产综合久久男男| 日日摸夜夜添添出白浆| 免费在线观看污污污网站| 久久精品熟女亚洲av色| 日韩国产欧美亚洲一区| 精品人妻少妇免费久久蜜臀av| 成人午夜激情福利动态| 国产白丝精品爽爽久久| 美国一级二级三级黄片|