diff --git a/PicoZCache.php b/PicoZCache.php index 71e9a7d..a02be5c 100644 --- a/PicoZCache.php +++ b/PicoZCache.php @@ -20,32 +20,19 @@ 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) { + $query = (!empty($_GET)) ? '__'.md5(serialize($_GET)) : null; //replace any character except numbers and digits with a '-' to form valid file names - $this->cacheFileName = $this->cacheDir . preg_replace('/[^A-Za-z0-9_\-]/', '_', $url) . '.html'; + $this->cacheFileName = $this->cacheDir . preg_replace('/[^A-Za-z0-9_\-]/', '_', $url.$query) . '.html'; //if a cached file exists and the cacheTime is not expired, load the file and exit if ($this->doCache && file_exists($this->cacheFileName) && (time() - filemtime($this->cacheFileName)) < $this->cacheTime) { 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