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

利用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一区二区| 少妇高潮视频在线观看| 在线播放精品免费不卡| 在线免费观看日本91| 日本一级二级三级在线看| 久久人人97超碰人人爱一久久精品| 亚洲欧美综合日韩综合久久久| 91精品人妻二区三区| 日本在线中文字幕乱码| 国产三级传媒视频在线观看| 亚洲永久免费精品一区二区三区 | 欧美日韩在线观看不卡视频| 人妻操人人妻中出av| 欧美一区二区三在线| 亚洲激情人妻小说网| 日本东京热加勒比视频| 日本一区二区 视频| 亚洲伦理一区二区三区中文| 蜜臀99久久精品久久久| 一区二区三区免费视频少妇| 99热这里只有精品最新| 亚洲综合一区二区三区不卡| 亚洲黄色片在线播放| 强暴美女视频大全久久久| 国产精品久久一国产精品| 国产 亚洲 一区 二区| 亚洲国产精品日韩专区av有中文| 熟女俱乐部五十路六十路| 欧美国产精品中文字幕| 国产亚洲av看码精品永久| 人妻中文字幕精品系列| 激情啪啪啪的免费网站| 国产一区在线免费在线观看| 国产我不卡在线观看免费| 日韩丰满少妇在线观看| 伦理中文字幕一区二区| 日韩欧美一区二区免费| 欧美精品福利一区二区|