-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Implement document cache manager (#1401)
Co-authored-by: Sebastian Meyer <[email protected]>
- Loading branch information
1 parent
7b95dff
commit c6b4973
Showing
3 changed files
with
114 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
/** | ||
* (c) Kitodo. Key to digital objects e.V. <[email protected]> | ||
* | ||
* This file is part of the Kitodo and TYPO3 projects. | ||
* | ||
* @license GNU General Public License version 3 or later. | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Kitodo\Dlf\Common; | ||
|
||
use TYPO3\CMS\Core\Cache\CacheManager; | ||
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* DocumentCacheManager class for the 'dlf' extension | ||
* | ||
* @package TYPO3 | ||
* @subpackage dlf | ||
* | ||
* @access public | ||
*/ | ||
class DocumentCacheManager | ||
{ | ||
/** | ||
* @var FrontendInterface | ||
*/ | ||
protected $cache; | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('tx_dlf_doc'); | ||
} | ||
|
||
/** | ||
* Get document instance from cache or false if not found. | ||
* | ||
* @access public | ||
* | ||
* @param string $location | ||
* | ||
* @return AbstractDocument|false | ||
*/ | ||
public function get(string $location) | ||
{ | ||
return $this->cache->get($this->getIdentifier($location)); | ||
} | ||
|
||
/** | ||
* Remove all documents from cache. | ||
* | ||
* @access public | ||
* | ||
* @return void | ||
*/ | ||
public function flush(): void | ||
{ | ||
$this->cache->flush(); | ||
} | ||
|
||
/** | ||
* Remove single document from cache. | ||
* | ||
* @access public | ||
* | ||
* @param string $location | ||
* | ||
* @return void | ||
*/ | ||
public function remove(string $location): void | ||
{ | ||
$this->cache->remove($this->getIdentifier($location)); | ||
} | ||
|
||
/** | ||
* Set cache for document instance. | ||
* | ||
* @access public | ||
* | ||
* @param string $location | ||
* @param AbstractDocument $currentDocument | ||
* | ||
* @return void | ||
*/ | ||
public function set(string $location, AbstractDocument $currentDocument): void | ||
{ | ||
$this->cache->set($this->getIdentifier($location), $currentDocument); | ||
} | ||
|
||
/** | ||
* Get cache identifier for document location. | ||
* | ||
* @access private | ||
* | ||
* @param string $location | ||
* | ||
* @return string | ||
*/ | ||
private function getIdentifier(string $location): string | ||
{ | ||
return hash('md5', $location); | ||
} | ||
} |