1 | <?php |
||
17 | class PostRelatedCacheManager extends BasicCacheManager |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * @type string |
||
22 | */ |
||
23 | const POST_CACHE_PREFIX = 'ee_cache_post_'; |
||
24 | |||
25 | /** |
||
26 | * wp-option option_name for tracking post related cache |
||
27 | * |
||
28 | * @type string |
||
29 | */ |
||
30 | const POST_CACHE_OPTIONS_KEY = 'ee_post_cache'; |
||
31 | |||
32 | |||
33 | |||
34 | /** |
||
35 | * PostRelatedCacheManager constructor. |
||
36 | * |
||
37 | * @param CacheStorageInterface $cache_storage |
||
38 | */ |
||
39 | 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 | * @return array |
||
60 | */ |
||
61 | protected function getPostRelatedCache() |
||
74 | |||
75 | |||
76 | /** |
||
77 | * @param array $post_related_cache |
||
78 | */ |
||
79 | protected function updatePostRelatedCache(array $post_related_cache = array()) |
||
83 | |||
84 | |||
85 | /** |
||
86 | * If you are caching content that pertains to a Post of any type, |
||
87 | * then it is recommended to pass the post id and cache id prefix to this method |
||
88 | * so that it can be added to the post related cache tracking. |
||
89 | * Then, whenever that post is updated, the cache will automatically be deleted, |
||
90 | * which helps to ensure that outdated cache content will not be served |
||
91 | * |
||
92 | * @param int $post_ID [required] |
||
93 | * @param string $id_prefix [required] Appended to all cache IDs. Can be helpful in finding specific cache types. |
||
94 | * May also be helpful to include an additional specific identifier, |
||
95 | * such as a post ID as part of the $id_prefix so that individual caches |
||
96 | * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
||
97 | * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
||
98 | */ |
||
99 | public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix) |
||
113 | |||
114 | |||
115 | |||
116 | /** |
||
117 | * callback hooked into the WordPress "save_post" action |
||
118 | * deletes any cache content associated with the post |
||
119 | * |
||
120 | * @param int $post_ID [required] |
||
121 | */ |
||
122 | public function clearPostRelatedCache($post_ID) |
||
140 | |||
141 | |||
142 | } |
||
143 | // End of file PostRelatedCacheManager.php |
||
145 |