PHP檔案快取內容儲存格式例項分析

2022-10-06 11:51:15 字數 1000 閱讀 6803

1、php檔案快取內容儲存格式

php檔案快取內容儲存格式主要有三種:

(1)變數 var_export 格式化成php正常的賦值書寫格式;

(2)變數 serialize 序列化之後儲存,用的時候反序列化;

(3)變數 json_encode格式化之後儲存,用的時候json_decode

網際網路上測試結果是:serialize格式的檔案解析效率大於json,json的解析效率大於php正常賦值。

所以我們要是快取資料建議採用序列化的形式解析資料會更快。

2、php檔案快取的簡單案例

<?php class cache_driver else

} //判斷key值對應的檔案是否存在,如果存在,讀取value值,value以序列化儲存

public function get($id)

$data = @file_get_contents($this->_cache_path . $id);

$data = unserialize($data);

if (!is_array($data) || !isset($data['time']) || !isset($data['ttl']))

if ($data['ttl'] > 0 && time() > $data['time'] + $data['ttl'])

return $data['data'];

} //設定快取資訊,rnlfpws根據key值,生成相應的快取檔案

public function set($id, $data, $ttl = 60)

return false;

} //根據key值,刪除快取檔案

public function delete($id)

public function clean()

@closedir($dh);

return true;

}}本文標題: php檔案快取內容儲存格式例項分析

本文位址:

PHP快取例項

cache.php 如下 php cachefile 判斷當前頁cache是否存在 且 cache功能是否開啟 return file exists file and cacheenable and ischange 讀取cache function read 生成cache function wr...

PHP檔案快取包含三種格式

php檔案快取的速度一直是php程式設計師們關心的問題,他們一直在 著如何才能提高php檔案快取的效率來滿足自己的開發需求 php檔案快取內容儲存格式主要有三種 1.變數 var export 格式化成php正常的賦值書寫格式,用的時候直接include檔案 2.變數 serialize 序列化之後...

php 檔案快取

class cache return self instance 得到快取資訊 param string id return boolean array public static function get id file instance file id data instance fileget...