| | |
| | | <?php |
| | | namespace JVBase\blocks; |
| | | |
| | | use JVBase\managers\CacheManager; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\forms\TaxonomySelector; |
| | | use JVBase\meta\MetaManager; |
| | | use WP_Block; |
| | |
| | | |
| | | class MenuBlock |
| | | { |
| | | protected CacheManager $cache; |
| | | protected Cache $cache; |
| | | protected string $config; |
| | | protected string $type; |
| | | protected string $path = JVB_DIR . '/build/menu'; |
| | |
| | | |
| | | public function __construct() |
| | | { |
| | | $this->cache = CacheManager::for('menu', WEEK_IN_SECONDS)->connectTo('post', 'menu_item'); |
| | | $this->cache = Cache::for('menu', WEEK_IN_SECONDS)->connectTo('post', 'menu_item'); |
| | | add_action('init', [ $this, 'registerBlock' ]); |
| | | } |
| | | |
| | |
| | | return ''; |
| | | } |
| | | $key = $this->cache->generateKey($this->params); |
| | | $cache = $this->cache->get($key); |
| | | if ($cache) { |
| | | return $cache; |
| | | } |
| | | |
| | | ob_start(); |
| | | $this->renderBlock(); |
| | | $content = ob_get_clean(); |
| | | $this->cache->set($key, $content); |
| | | return $content; |
| | | return $this->cache->remember( |
| | | $key, |
| | | function() { |
| | | ob_start(); |
| | | $this->renderBlock(); |
| | | return ob_get_clean(); |
| | | } |
| | | ); |
| | | } |
| | | |
| | | protected function renderBlock():void |