|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Phact\Router; |
|
4
|
|
|
|
|
5
|
|
|
use DateInterval; |
|
6
|
|
|
use Psr\SimpleCache\CacheInterface; |
|
7
|
|
|
|
|
8
|
|
|
trait CacheAwareTrait |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var CacheInterface */ |
|
11
|
|
|
protected $cache; |
|
12
|
|
|
|
|
13
|
|
|
/** @var string */ |
|
14
|
|
|
protected $cacheKey = 'routes'; |
|
15
|
|
|
|
|
16
|
|
|
/** @var null|int|DateInterval */ |
|
17
|
|
|
protected $cacheTTL; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @inheritDoc |
|
21
|
|
|
*/ |
|
22
|
4 |
|
public function setCache(CacheInterface $cache): void |
|
23
|
|
|
{ |
|
24
|
4 |
|
$this->cache = $cache; |
|
25
|
4 |
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @inheritDoc |
|
29
|
|
|
*/ |
|
30
|
1 |
|
public function setCacheKey(string $key = 'routes'): void |
|
31
|
|
|
{ |
|
32
|
1 |
|
$this->cacheKey = $key; |
|
33
|
1 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @inheritDoc |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function setCacheTTL($ttl = 60): void |
|
39
|
|
|
{ |
|
40
|
1 |
|
$this->cacheTTL = $ttl; |
|
41
|
1 |
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|