1 | <?php |
||
19 | class BasicCacheManager implements CacheManagerInterface |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * @type string |
||
24 | */ |
||
25 | const CACHE_PREFIX = 'ee_cache_'; |
||
26 | |||
27 | |||
28 | /** |
||
29 | * @var CacheStorageInterface $cache_storage |
||
30 | */ |
||
31 | private $cache_storage; |
||
32 | |||
33 | |||
34 | |||
35 | /** |
||
36 | * BasicCacheManager constructor. |
||
37 | * |
||
38 | * @param CacheStorageInterface $cache_storage [required] |
||
39 | */ |
||
40 | public function __construct(CacheStorageInterface $cache_storage) |
||
44 | |||
45 | |||
46 | |||
47 | /** |
||
48 | * returns a string that will be prepended to all cache identifiers |
||
49 | * |
||
50 | * @return string |
||
51 | */ |
||
52 | public function cachePrefix() |
||
56 | |||
57 | |||
58 | |||
59 | /** |
||
60 | * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
||
61 | * May also be helpful to include an additional specific identifier, |
||
62 | * such as a post ID as part of the $id_prefix so that individual caches |
||
63 | * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
||
64 | * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
||
65 | * @param string $cache_id [required] Additional identifying details that make this cache unique. |
||
66 | * It is advisable to use some of the actual data |
||
67 | * that is used to generate the content being cached, |
||
68 | * in order to guarantee that the cache id is unique for that content. |
||
69 | * The cache id will be md5'd before usage to make it more db friendly, |
||
70 | * and the entire cache id string will be truncated to 190 characters. |
||
71 | * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
||
72 | * necessary, |
||
73 | * we wrap our content creation in a Closure so that it is not executed until needed. |
||
74 | * @param int $expiration |
||
75 | * @return Closure|mixed |
||
76 | */ |
||
77 | public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS) |
||
111 | |||
112 | |||
113 | |||
114 | /** |
||
115 | * Generates a unique identifier string for the cache |
||
116 | * |
||
117 | * @param string $id_prefix [required] see BasicCacheManager::get() |
||
118 | * @param string $cache_id [required] see BasicCacheManager::get() |
||
119 | * @return string |
||
120 | */ |
||
121 | private function generateCacheIdentifier($id_prefix, $cache_id) |
||
130 | |||
131 | |||
132 | |||
133 | /** |
||
134 | * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
||
135 | * or a specific ID targeting a single cache item |
||
136 | * @return void |
||
137 | */ |
||
138 | public function clear($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 | * @param string $type |
||
152 | * @return string |
||
153 | */ |
||
154 | private function displayCacheNotice($cache_id, $type) { |
||
164 | |||
165 | } |
||
166 | // End of file BasicCacheManager.php |
||
168 |