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 | 80 | 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 | 78 | 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 | 62 | public function makeCache(Vars $vars) |
|
141 | |||
142 | /** |
||
143 | * Returns if cache is on or off |
||
144 | * |
||
145 | * @return bool Is cache on or off |
||
146 | */ |
||
147 | 68 | public function getProvide() |
|
151 | |||
152 | /** |
||
153 | * Set the cache on or off |
||
154 | * |
||
155 | * @param bool $provide Does the cache want to be on or off |
||
156 | * |
||
157 | * @return \M1\Vars\Cache\CacheProvider |
||
158 | */ |
||
159 | 80 | public function setProvide($provide) |
|
164 | |||
165 | /** |
||
166 | * Returns if the cache has been attempted |
||
167 | * |
||
168 | * @return bool Has the cache been attempted |
||
169 | */ |
||
170 | 7 | public function getAttempted() |
|
174 | |||
175 | /** |
||
176 | * Returns how long the cache lasts for |
||
177 | * |
||
178 | * @return int Cache expire time |
||
179 | */ |
||
180 | 2 | public function getExpire() |
|
184 | |||
185 | /** |
||
186 | * Returns how long the cache lasts for |
||
187 | * |
||
188 | * @return int Cache expire time |
||
189 | */ |
||
190 | 62 | public function isHit() |
|
194 | |||
195 | /** |
||
196 | * Returns when the cache was made |
||
197 | * |
||
198 | * @return int Cache creation time |
||
199 | */ |
||
200 | 3 | public function getTime() |
|
204 | |||
205 | /** |
||
206 | * Sets the time when the Vars was cached |
||
207 | * |
||
208 | * @param int $time Time when vars cached was created |
||
209 | * |
||
210 | * @return \M1\Vars\Cache\CacheProvider The cacheProvider object |
||
211 | */ |
||
212 | 62 | public function setTime($time) |
|
217 | |||
218 | /** |
||
219 | * Returns the loaded Vars object |
||
220 | * |
||
221 | * @return \M1\Vars\Vars The loaded Vars object |
||
222 | */ |
||
223 | 3 | public function getLoadedVars() |
|
227 | } |
||
228 |