From f464e024c7876308fa0d890ca4262c7dc23b6888 Mon Sep 17 00:00:00 2001 From: Landrok Date: Mon, 10 Feb 2014 00:59:38 +0100 Subject: [PATCH] Cache made by var_export (performances) Added: - choice of hash algo (for large sets of cache) - cache made by var_export instead of json_encode - fs cache is now put in a php file to be opcode cached by APC (PHP<5.5) or OPcache (PHP>=5.5) var_export conv : if your cache values are only numbers, var_export will create larger files. But in this project, cache are mostly characters. So, your files will be smaller because they won't be 'json encoded'. - No json_encode/decode : better performances Other things : var_export returns the exact PHP code so that it could be cached as opcode. --- caches/FileCache.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/caches/FileCache.php b/caches/FileCache.php index 594343d3..19a01bd0 100644 --- a/caches/FileCache.php +++ b/caches/FileCache.php @@ -1,14 +1,20 @@ isPrepareCache(); - $datas = json_decode(file_get_contents($this->getCacheFile()),true); + $datas = include( $this->getCacheFile() ); $items = array(); foreach($datas as $aData){ $item = new \Item(); @@ -24,7 +30,7 @@ class FileCache extends CacheAbstract{ public function saveData($datas){ $this->isPrepareCache(); - file_put_contents($this->getCacheFile(), json_encode($datas)); + file_put_contents($this->getCacheFile(), 'isPrepareCache(); $stringToEncode = $_SERVER['REQUEST_URI'] . http_build_query($this->param); - return hash('sha1', $stringToEncode) . '.cache'; + return hash($this->hash_algo , $stringToEncode) . '.cache.php'; } -} \ No newline at end of file +}