1 | <?php |
||
18 | class BasicCacheManager implements CacheManagerInterface |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @type string |
||
23 | */ |
||
24 | const CACHE_PREFIX = 'ee_cache_'; |
||
25 | |||
26 | /** |
||
27 | * set to true to monitor when content is being served from cache or not |
||
28 | * |
||
29 | * @type boolean |
||
30 | */ |
||
31 | const DEBUG = false; |
||
32 | |||
33 | /** |
||
34 | * @var CacheStorageInterface $cache_storage |
||
35 | */ |
||
36 | private $cache_storage; |
||
37 | |||
38 | |||
39 | |||
40 | /** |
||
41 | * BasicCacheManager constructor. |
||
42 | * |
||
43 | * @param CacheStorageInterface $cache_storage [required] |
||
44 | */ |
||
45 | public function __construct(CacheStorageInterface $cache_storage) |
||
49 | |||
50 | |||
51 | |||
52 | /** |
||
53 | * returns a string that will be prepended to all cache identifiers |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | public function cachePrefix() |
||
61 | |||
62 | |||
63 | |||
64 | /** |
||
65 | * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
||
66 | * May also be helpful to include an additional specific identifier, |
||
67 | * such as a post ID as part of the $id_prefix so that individual caches |
||
68 | * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
||
69 | * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
||
70 | * @param string $cache_id [required] Additional identifying details that make this cache unique. |
||
71 | * It is advisable to use some of the actual data |
||
72 | * that is used to generate the content being cached, |
||
73 | * in order to guarantee that the cache id is unique for that content. |
||
74 | * The cache id will be md5'd before usage to make it more db friendly, |
||
75 | * and the entire cache id string will be truncated to 190 characters. |
||
76 | * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
||
77 | * necessary, |
||
78 | * we wrap our content creation in a Closure so that it is not executed until needed. |
||
79 | * @param int $expiration |
||
80 | * @return Closure|mixed |
||
81 | */ |
||
82 | public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS) |
||
117 | |||
118 | |||
119 | |||
120 | /** |
||
121 | * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
||
122 | * or a specific ID targeting a single cache item |
||
123 | * @return void |
||
124 | */ |
||
125 | public function clear($cache_id) |
||
132 | |||
133 | |||
134 | |||
135 | } |
||
136 | // End of file BasicCacheManager.php |
||
137 | // Location: core/services/cache/BasicCacheManager.php |