1<?php 2 3use dokuwiki\Extension\ActionPlugin; 4use dokuwiki\Extension\EventHandler; 5use dokuwiki\Extension\Event; 6 7class action_plugin_approve_cache extends ActionPlugin 8{ 9 /** 10 * @inheritDoc 11 */ 12 public function register(EventHandler $controller) 13 { 14 $controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'handle_parser_cache_use'); 15 } 16 /** 17 * @param Event $event 18 * @param mixed $param 19 */ 20 public function handle_parser_cache_use(Event $event, $param) 21 { 22 /** @var cache_renderer $cache */ 23 $cache = $event->data; 24 25 if(!$cache->page) return; 26 //purge only xhtml cache 27 if($cache->mode != 'xhtml') return; 28 29 //Check if it is plugins 30 $approve = p_get_metadata($cache->page, 'plugin approve'); 31 if(!$approve) return; 32 33 if ($approve['dynamic_approver']) { 34 $cache->_nocache = true; 35 } elseif ($approve['approve_table']) { 36 try { 37 /** @var helper_plugin_approve_db $db */ 38 $db = $this->loadHelper('approve_db'); 39 $cache->depends['files'][] = $db->getDbFile(); 40 } catch (Exception $e) { 41 msg($e->getMessage(), -1); 42 return; 43 } 44 } 45 } 46} 47