From 0b41a3b3ec48d1ee1d304e021da1000003aaa062 Mon Sep 17 00:00:00 2001 From: Georg Duemmler Date: Fri, 9 Sep 2016 12:20:46 +0200 Subject: [PATCH] add cache utility --- Classes/Utility/CacheUtility.php | 29 ++++++++++++++++++++--------- ext_emconf.php | 2 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Classes/Utility/CacheUtility.php b/Classes/Utility/CacheUtility.php index cac19fd..63819f8 100644 --- a/Classes/Utility/CacheUtility.php +++ b/Classes/Utility/CacheUtility.php @@ -30,7 +30,7 @@ * * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -class CacheUtility extends ActionController +class CacheUtility { /** * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager @@ -72,6 +72,11 @@ class CacheUtility extends ActionController */ protected $gpVars; + /** + * @var string + */ + protected $cacheIdentifier = null; + /** * CacheUtility constructor. @@ -79,8 +84,6 @@ class CacheUtility extends ActionController */ public function __construct($extKey) { - parent::__construct(); - $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); $this->request = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Mvc\\Request'); @@ -99,12 +102,11 @@ public function __construct($extKey) /** * getCache function. * - * @param mixed $hashVars (default: null) * @return mixed */ - public function getCache($hashVars = null) + public function getCache() { - $cacheID = $this->getCacheID(array($hashVars)); + $cacheID = $this->getCacheID(array($this->cacheIdentifier)); $data = PageRepository::getHash($cacheID); return !$data ? false : unserialize($data); } @@ -114,18 +116,27 @@ public function getCache($hashVars = null) * setCache function. * * @param mixed $data (default: null) - * @param mixed $hashVars (default: null) * @return mixed */ - public function setCache($data = null, $hashVars = null) + public function setCache($data = null) { $lifetime = mktime(23, 59, 59) + 1 - time(); - $cacheID = $this->getCacheID(array($hashVars)); + $cacheID = $this->getCacheID(array($this->cacheIdentifier)); PageRepository::storeHash($cacheID, serialize($data), $this->extKey . '_cache', $lifetime); return $data; } + /** + * @param array $array + */ + public function setCacheIdentifier($array) + { + $this->cacheIdentifier = md5(json_encode($array)); + } + + + /** * getCacheID function. diff --git a/ext_emconf.php b/ext_emconf.php index fbbbeab..9d32b83 100755 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -39,7 +39,7 @@ 'uploadfolder' => '0', 'createDirs' => '', 'clearCacheOnLoad' => 0, - 'version' => '2.0.1', + 'version' => '2.0.2', 'constraints' => array( 'depends' => array( 'typo3' => '6.2.0-7.99.99',