From 82ed2c5ffbde90e7c1fa386ecf9e110829ffa043 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sun, 16 Oct 2016 11:08:08 +0200 Subject: [PATCH] [FileCache] Change output format to JSON JSON format does not serialize object instances, which we don't want anyways, and improves readability. The hashing algorithm changed to md5 to prevent collisions with existing cache files --- caches/FileCache.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/caches/FileCache.php b/caches/FileCache.php index ce8394e..79ed6d0 100644 --- a/caches/FileCache.php +++ b/caches/FileCache.php @@ -8,12 +8,11 @@ class FileCache implements CacheInterface { protected $param; public function loadData(){ - $datas = unserialize(file_get_contents($this->getCacheFile())); - return $datas; + return json_decode(file_get_contents($this->getCacheFile()), true); } public function saveData($datas){ - $writeStream = file_put_contents($this->getCacheFile(), serialize($datas)); + $writeStream = file_put_contents($this->getCacheFile(), json_encode($datas, JSON_PRETTY_PRINT)); if(!$writeStream) { throw new \Exception("Cannot write the cache... Do you have the right permissions ?"); @@ -111,6 +110,6 @@ class FileCache implements CacheInterface { throw new \Exception('Call "setParameters" first!'); } - return hash('sha1', http_build_query($this->param)) . '.cache'; + return hash('md5', http_build_query($this->param)) . '.cache'; } }