1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Platine Template |
5
|
|
|
* |
6
|
|
|
* Platine Template is a template engine that has taken a lot of inspiration from Django. |
7
|
|
|
* |
8
|
|
|
* This content is released under the MIT License (MIT) |
9
|
|
|
* |
10
|
|
|
* Copyright (c) 2020 Platine Template |
11
|
|
|
* Copyright (c) 2014 Guz Alexander, http://guzalexander.com |
12
|
|
|
* Copyright (c) 2011, 2012 Harald Hanek, http://www.delacap.com |
13
|
|
|
* Copyright (c) 2006 Mateo Murphy |
14
|
|
|
* |
15
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
16
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
17
|
|
|
* in the Software without restriction, including without limitation the rights |
18
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
19
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
20
|
|
|
* furnished to do so, subject to the following conditions: |
21
|
|
|
* |
22
|
|
|
* The above copyright notice and this permission notice shall be included in all |
23
|
|
|
* copies or substantial portions of the Software. |
24
|
|
|
* |
25
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
26
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
27
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
28
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
29
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
30
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
31
|
|
|
* SOFTWARE. |
32
|
|
|
*/ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @file AbstractCache.php |
36
|
|
|
* |
37
|
|
|
* The Template cache base class |
38
|
|
|
* |
39
|
|
|
* @package Platine\Template\Cache |
40
|
|
|
* @author Platine Developers Team |
41
|
|
|
* @copyright Copyright (c) 2020 |
42
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
43
|
|
|
* @link http://www.iacademy.cf |
44
|
|
|
* @version 1.0.0 |
45
|
|
|
* @filesource |
46
|
|
|
*/ |
47
|
|
|
|
48
|
|
|
declare(strict_types=1); |
49
|
|
|
|
50
|
|
|
namespace Platine\Template\Cache; |
51
|
|
|
|
52
|
|
|
use Platine\Template\Configuration; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Class AbstractCache |
56
|
|
|
* @package Platine\Template\Cache |
57
|
|
|
*/ |
58
|
|
|
abstract class AbstractCache |
59
|
|
|
{ |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The cache expiration in second |
63
|
|
|
* @var int |
64
|
|
|
*/ |
65
|
|
|
protected int $expire = 3600; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* The cache prefix to use |
69
|
|
|
* @var string |
70
|
|
|
*/ |
71
|
|
|
protected string $prefix = '__template'; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* The configuration instance |
75
|
|
|
* @var Configuration |
76
|
|
|
*/ |
77
|
|
|
protected Configuration $config; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Create new instance |
81
|
|
|
* @param Configuration $config |
82
|
|
|
*/ |
83
|
|
|
public function __construct(Configuration $config) |
84
|
|
|
{ |
85
|
|
|
$this->config = $config; |
86
|
|
|
|
87
|
|
|
$this->expire = $config->getCacheExpire(); |
88
|
|
|
$this->prefix = $config->getCachePrefix(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Return the cache stored value |
93
|
|
|
* @param string $key |
94
|
|
|
* @param bool $unserialize |
95
|
|
|
* @return mixed|bool |
96
|
|
|
*/ |
97
|
|
|
abstract public function read(string $key, bool $unserialize = true); |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Whether the cache exists |
101
|
|
|
* @param string $key |
102
|
|
|
* @return bool |
103
|
|
|
*/ |
104
|
|
|
abstract public function exists(string $key): bool; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Save the cache data |
108
|
|
|
* @param string $key |
109
|
|
|
* @param mixed $value |
110
|
|
|
* @param bool $serialize |
111
|
|
|
* @return bool |
112
|
|
|
*/ |
113
|
|
|
abstract public function write(string $key, $value, bool $serialize = true): bool; |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Delete all cache data |
118
|
|
|
* @param bool $expired |
119
|
|
|
* @return bool |
120
|
|
|
*/ |
121
|
|
|
abstract public function flush(bool $expired = false): bool; |
122
|
|
|
} |
123
|
|
|
|