1 | <?php |
||
19 | class BasicCacheManager implements CacheManagerInterface |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * @type string |
||
24 | */ |
||
25 | const CACHE_PREFIX = 'ee_cache_'; |
||
26 | |||
27 | /** |
||
28 | * set to true to monitor when content is being served from cache or not |
||
29 | * |
||
30 | * @type boolean |
||
31 | */ |
||
32 | const DEBUG = false; |
||
33 | |||
34 | /** |
||
35 | * @var CacheStorageInterface $cache_storage |
||
36 | */ |
||
37 | private $cache_storage; |
||
38 | |||
39 | /** |
||
40 | * @var SessionIdentifierInterface $session |
||
41 | */ |
||
42 | private $session; |
||
43 | |||
44 | |||
45 | |||
46 | /** |
||
47 | * BasicCacheManager constructor. |
||
48 | * |
||
49 | * @param CacheStorageInterface $cache_storage [required] |
||
50 | * @param SessionIdentifierInterface $session |
||
51 | */ |
||
52 | public function __construct(CacheStorageInterface $cache_storage, SessionIdentifierInterface $session) |
||
57 | |||
58 | |||
59 | |||
60 | /** |
||
61 | * returns a string that will be prepended to all cache identifiers |
||
62 | * |
||
63 | * @return string |
||
64 | */ |
||
65 | public function cachePrefix() |
||
69 | |||
70 | |||
71 | |||
72 | /** |
||
73 | * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
||
74 | * May also be helpful to include an additional specific identifier, |
||
75 | * such as a post ID as part of the $id_prefix so that individual caches |
||
76 | * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
||
77 | * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
||
78 | * @param string $cache_id [required] Additional identifying details that make this cache unique. |
||
79 | * It is advisable to use some of the actual data |
||
80 | * that is used to generate the content being cached, |
||
81 | * in order to guarantee that the cache id is unique for that content. |
||
82 | * The cache id will be md5'd before usage to make it more db friendly, |
||
83 | * and the entire cache id string will be truncated to 190 characters. |
||
84 | * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
||
85 | * necessary, |
||
86 | * we wrap our content creation in a Closure so that it is not executed until needed. |
||
87 | * @param int $expiration |
||
88 | * @return Closure|mixed |
||
89 | */ |
||
90 | public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS) |
||
124 | |||
125 | |||
126 | |||
127 | /** |
||
128 | * Generates a unique identifier string for the cache |
||
129 | * |
||
130 | * @param string $id_prefix [required] see BasicCacheManager::get() |
||
131 | * @param string $cache_id [required] see BasicCacheManager::get() |
||
132 | * @return string |
||
133 | */ |
||
134 | private function generateCacheIdentifier($id_prefix, $cache_id) |
||
145 | |||
146 | |||
147 | |||
148 | /** |
||
149 | * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
||
150 | * or a specific ID targeting a single cache item |
||
151 | * @return void |
||
152 | */ |
||
153 | public function clear($cache_id) |
||
160 | |||
161 | |||
162 | |||
163 | /** |
||
164 | * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
||
165 | * or a specific ID targeting a single cache item |
||
166 | * @param string $type |
||
167 | * @return string |
||
168 | */ |
||
169 | private function displayCacheNotice($cache_id, $type) { |
||
179 | |||
180 | } |
||
181 | // End of file BasicCacheManager.php |
||
182 | // Location: core/services/cache/BasicCacheManager.php |