Completed
Push — master ( 11f33f...14005b )
by Tim
10:31 queued 07:40
created

ApiResultToCachePersister::persist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 4
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
/**
4
 * Class ApiResultToCachePersister
5
 */
6
7
namespace HDNET\OnpageIntegration\Persister;
8
9
use TYPO3\CMS\Core\Cache\CacheManager;
10
use TYPO3\CMS\Core\Utility\GeneralUtility;
11
12
/**
13
 * Class ApiResultToCachePersister
14
 */
15
class ApiResultToCachePersister
16
{
17
18
    const CACHE_ID_PREFIX = 'HDNET_onpage_extension';
19
20
    /**
21
     * @param string $data
22
     * @param string $key
23
     */
24
    public function persist($data, $key)
25
    {
26
        /** @var CacheManager $cacheManager */
27
        $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
28
        $cache = $cacheManager->getCache('onpage_extension');
29
        $cache->set($this->getIdentifier($key), json_encode($data));
30
    }
31
32
    /**
33
     * @param string $key
34
     *
35
     * @return string
36
     */
37
    public function getIdentifier($key)
38
    {
39
        $id = sha1(self::CACHE_ID_PREFIX . $key);
40
        return $id;
41
    }
42
}
43