ApiResultToCachePersister   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 31
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIdentifier() 0 5 1
A persist() 0 10 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
    const DEFAULT_CACHE_LIFETIME = 604800;
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
        if (!$cache->get('lastCrawlDate')) {
30
            $cache->set('lastCrawlDate', date('d.m.Y'));
31
        }
32
        $cache->set($this->getIdentifier($key), json_encode($data));
33
    }
34
35
    /**
36
     * @param string $key
37
     *
38
     * @return string
39
     */
40
    public function getIdentifier($key)
41
    {
42
        $id = sha1(self::CACHE_ID_PREFIX . $key);
43
        return $id;
44
    }
45
}
46