From d941fa41f6a353ad8eefa2e210c105cc545a1938 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 8 Oct 2016 15:21:10 +0200 Subject: [PATCH] [FileCache] Remove 'isPrepareCache' There is no need to check the absense of the parameters in all functions. Instead 'getCacheName' is the only function actually using the parameters and thus should check the availability. --- caches/FileCache.php | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/caches/FileCache.php b/caches/FileCache.php index 261fe0c3..2ece7e2d 100644 --- a/caches/FileCache.php +++ b/caches/FileCache.php @@ -7,14 +7,11 @@ class FileCache implements CacheInterface { protected $param; public function loadData(){ - $this->isPrepareCache(); $datas = unserialize(file_get_contents($this->getCacheFile())); return $datas; } public function saveData($datas){ - $this->isPrepareCache(); - $writeStream = file_put_contents($this->getCacheFile(), serialize($datas)); if(!$writeStream) { @@ -25,8 +22,6 @@ class FileCache implements CacheInterface { } public function getTime(){ - $this->isPrepareCache(); - $cacheFile = $this->getCacheFile(); if(file_exists($cacheFile)){ return filemtime($cacheFile); @@ -65,19 +60,6 @@ class FileCache implements CacheInterface { return $this; } - /** - * Cache is prepared ? - * Note : Cache name is based on request information, then cache must be prepare before use - * @return \Exception|true - */ - protected function isPrepareCache(){ - if(is_null($this->param)){ - throw new \Exception('Please feed "setParameters" method before try to load'); - } - - return true; - } - /** * Return cache path (and create if not exist) * @return string Cache path @@ -106,7 +88,10 @@ class FileCache implements CacheInterface { * return string */ protected function getCacheName(){ - $this->isPrepareCache(); + if(is_null($this->param)){ + throw new \Exception('Call "setParameters" first!'); + } + return hash('sha1', http_build_query($this->param)) . '.cache'; } }