From d85e13d6ace046204bbfa9687dd54a792d56cb4b Mon Sep 17 00:00:00 2001 From: marcus-at-localhorst Date: Thu, 15 Aug 2019 12:25:06 +0200 Subject: [PATCH 1/2] Use v2 way to load config Yaml config should look like this now ``` PicoZCache: enabled: true # True/False if cache is enabled dir: cache/html/ # Directory where cache should be saved time: 604800 # Interval between caching (period from one to second cache) in seconds, here is 7 days = 60 * 60 * 24 * 7. xhtml_output: false # If true, XHTML Content-Type header will be sent when loading cache page ``` --- PicoZCache.php | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/PicoZCache.php b/PicoZCache.php index 71e9a7d..c20c9b6 100644 --- a/PicoZCache.php +++ b/PicoZCache.php @@ -20,27 +20,13 @@ class PicoZCache extends AbstractPicoPlugin private $cacheXHTML = false; private $cacheFileName; - public function onConfigLoaded(array &$settings) - { - if (isset($config['cache_dir'])) { - - // ensure cache_dir ends with '/' - $lastchar = substr($config['cache_dir'], -1); - if ($lastchar !== '/') { - $config['cache_dir'] = $config['cache_dir'].'/'; - } - $this->cacheDir = $config['cache_dir']; - } - if (isset($config['cache_time'])) { - $this->cacheTime = $config['cache_time']; - } - if (isset($config['cache_enabled'])) { - $this->doCache = $config['cache_enabled']; - } - if (isset($config['cache_xhtml_output'])) { - $this->cacheXHTML = $config['cache_xhtml_output']; - } - } + public function onConfigLoaded(array &$config) + { + $this->doCache = $this->getPluginConfig('enabled', false); + $this->cacheTime = $this->getPluginConfig('time', 604800); + $this->cacheXHTML = $this->getPluginConfig('xhtml_output', false); + $this->cacheDir = trim($this->getPluginConfig('dir', 'content/cache/'),'/').'/'; + } public function onRequestUrl(&$url) { From 699203e31fb0ec3d9101e4b04f33b5a2d10e9dac Mon Sep 17 00:00:00 2001 From: marcus-at-localhorst Date: Thu, 15 Aug 2019 12:26:20 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0e362b1..f71fbf6 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,11 @@ To install the Pico Cache plugin, simply download the `PicoZCache.php` and put i In config.yml you can change default caching settings: ```yaml -cache_enabled: true # True/False if cache is enabled -cache_dir: content/cache/ # Directory where cache should be saved -cache_time: 604800 # Interval between caching (period from one to second cache) in seconds, here is 7 days = 60 * 60 * 24 * 7. -cache_xhtml_output: false # If true, XHTML Content-Type header will be sent when loading cache page +PicoZCache: + enabled: true # True/False if cache is enabled + dir: cache/html/ # Directory where cache should be saved + time: 604800 # Interval between caching (period from one to second cache) in seconds, here is 7 days = 60 * 60 * 24 * 7. + xhtml_output: false # If true, XHTML Content-Type header will be sent when loading cache page ``` ## Cache clearing