Skip to content
This repository has been archived by the owner on Jun 26, 2018. It is now read-only.

Commit

Permalink
add cache utility
Browse files Browse the repository at this point in the history
  • Loading branch information
Georg Duemmler committed Sep 9, 2016
1 parent 5089834 commit 0b41a3b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
29 changes: 20 additions & 9 deletions Classes/Utility/CacheUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,15 +72,18 @@ class CacheUtility extends ActionController
*/
protected $gpVars;

/**
* @var string
*/
protected $cacheIdentifier = null;


/**
* CacheUtility constructor.
* @param string $extKey
*/
public function __construct($extKey)
{
parent::__construct();

$this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$this->request = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Mvc\\Request');

Expand All @@ -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);
}
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 0b41a3b

Please sign in to comment.