-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheTrait.php
More file actions
57 lines (49 loc) · 1.3 KB
/
CacheTrait.php
File metadata and controls
57 lines (49 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* This file is part of the sci/cacheable package.
*
* (c) Sascha Schimke <sascha@schimke.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sci\Cacheable;
use Psr\Cache\CacheItemPoolInterface;
trait CacheTrait
{
/** @var CacheItemPoolInterface */
private $cache;
/** @var int */
private $lifetime;
/** @var string */
private $namespace;
/**
* @param CacheItemPoolInterface $cache
* @param int $lifetime
* @param string $namespace
*/
public function setCache(CacheItemPoolInterface $cache, $lifetime = null, $namespace = null)
{
$this->cache = $cache;
$this->lifetime = $lifetime;
$this->namespace = $namespace;
}
/**
* @param int|null $lifetime
*
* @return $this
*/
public function cache($lifetime = null)
{
return is_null($this->cache) ? $this : $this->createCacheProxy($lifetime);
}
/**
* @param int|null $lifetime
*
* @return CacheProxy
*/
private function createCacheProxy($lifetime)
{
return new CacheProxy($this->cache, $this, is_null($lifetime) ? $this->lifetime : $lifetime, $this->namespace);
}
}