1 | <?php |
||
29 | class CacheProvider |
||
30 | { |
||
31 | /** |
||
32 | * Used for path functions and variables |
||
33 | */ |
||
34 | use PathTrait; |
||
35 | |||
36 | /** |
||
37 | * Has the cache been attempted |
||
38 | * |
||
39 | * @var bool $attempted |
||
40 | */ |
||
41 | private $attempted = false; |
||
42 | |||
43 | /** |
||
44 | * How long for the cache to be fresh |
||
45 | * |
||
46 | * @var int $expire |
||
47 | */ |
||
48 | private $expire; |
||
49 | |||
50 | /** |
||
51 | * Has the cache been found |
||
52 | * |
||
53 | * @var bool $hit |
||
54 | */ |
||
55 | private $hit = false; |
||
56 | |||
57 | /** |
||
58 | * The loaded Vars object from cache |
||
59 | * |
||
60 | * @var \M1\Vars\Vars $loaded_vars |
||
61 | */ |
||
62 | private $loaded_vars; |
||
63 | |||
64 | /** |
||
65 | * The cache file name |
||
66 | * |
||
67 | * @var string $name |
||
68 | */ |
||
69 | private $name; |
||
70 | |||
71 | /** |
||
72 | * Is the cache turned on |
||
73 | * |
||
74 | * @var boolean $provide |
||
75 | */ |
||
76 | private $provide; |
||
77 | |||
78 | /** |
||
79 | * If cached, the time when the class was cached |
||
80 | * |
||
81 | * @var int $time |
||
82 | */ |
||
83 | private $time; |
||
84 | |||
85 | /** |
||
86 | * Creates a new instance of the cacheProvider for Vars |
||
87 | * |
||
88 | * @param string|array $resource The main configuration resource |
||
89 | * @param array $options The options being used for Vars |
||
90 | */ |
||
91 | 86 | public function __construct($resource, $options) |
|
99 | |||
100 | /** |
||
101 | * Checks the cache to see if there is a valid cache available |
||
102 | * |
||
103 | * @return bool Returns true if has the cached resource |
||
104 | */ |
||
105 | 84 | public function checkCache() |
|
119 | |||
120 | /** |
||
121 | * Load the cached file into $this->loaded_vars |
||
122 | */ |
||
123 | 3 | public function load() |
|
128 | |||
129 | /** |
||
130 | * Transfer the contents of the parent Vars object into a file for cache |
||
131 | * |
||
132 | * @param \M1\Vars\Vars $vars Parent vars object |
||
133 | * |
||
134 | * @codeCoverageIgnore |
||
135 | */ |
||
136 | public function makeCache(Vars $vars) |
||
148 | |||
149 | /** |
||
150 | * Returns if cache is on or off |
||
151 | * |
||
152 | * @return bool Is cache on or off |
||
153 | */ |
||
154 | 74 | public function getProvide() |
|
158 | |||
159 | /** |
||
160 | * Set the cache on or off |
||
161 | * |
||
162 | * @param bool $provide Does the cache want to be on or off |
||
163 | * |
||
164 | * @return \M1\Vars\Cache\CacheProvider |
||
165 | */ |
||
166 | 86 | public function setProvide($provide) |
|
171 | |||
172 | /** |
||
173 | * Returns if the cache has been attempted |
||
174 | * |
||
175 | * @return bool Has the cache been attempted |
||
176 | */ |
||
177 | 7 | public function getAttempted() |
|
181 | |||
182 | /** |
||
183 | * Returns how long the cache lasts for |
||
184 | * |
||
185 | * @return int Cache expire time |
||
186 | */ |
||
187 | 2 | public function getExpire() |
|
191 | |||
192 | /** |
||
193 | * Returns how long the cache lasts for |
||
194 | * |
||
195 | * @return int Cache expire time |
||
196 | */ |
||
197 | 66 | public function isHit() |
|
201 | |||
202 | /** |
||
203 | * Returns when the cache was made |
||
204 | * |
||
205 | * @return int Cache creation time |
||
206 | */ |
||
207 | 3 | public function getTime() |
|
211 | |||
212 | /** |
||
213 | * Sets the time when the Vars was cached |
||
214 | * |
||
215 | * @param int $time Time when vars cached was created |
||
216 | * |
||
217 | * @return \M1\Vars\Cache\CacheProvider The cacheProvider object |
||
218 | */ |
||
219 | 66 | public function setTime($time) |
|
224 | |||
225 | /** |
||
226 | * Returns the loaded Vars object |
||
227 | * |
||
228 | * @return \M1\Vars\Vars The loaded Vars object |
||
229 | */ |
||
230 | 3 | public function getLoadedVars() |
|
234 | } |
||
235 |