From 125bc1070505db1f7a55c70ede4b4e3de0272a13 Mon Sep 17 00:00:00 2001 From: Schlaefer Date: Sun, 10 Nov 2013 10:47:48 +0100 Subject: [PATCH 1/4] allows easear additional CacheSupportCachelets --- app/Lib/CacheSupport.php | 67 ++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/app/Lib/CacheSupport.php b/app/Lib/CacheSupport.php index 55572b124..2f517c366 100644 --- a/app/Lib/CacheSupport.php +++ b/app/Lib/CacheSupport.php @@ -4,18 +4,20 @@ class CacheSupport extends Object { protected $_Caches = []; + protected $_buildInCaches = [ + // php caches + 'ApcCacheSupportCachelet', + 'OpCacheSupportCachelet', + // application caches + 'CakeCacheSupportCachelet', + 'SaitoCacheSupportCachelet', + 'ThreadCacheSupportCachelet' + ]; + public function __construct() { - $this->addCache( - [ - // php caches - 'Apc' => 'ApcCacheSupportCachelet', - 'OpCache' => 'OpCacheSupportCachelet', - // application caches - 'Cake' => 'CakeCacheSupportCachelet', - 'Saito' => 'SaitoCacheSupportCachelet', - 'Thread' => 'ThreadCacheSupportCachelet' - ] - ); + foreach ($this->_buildInCaches as $_name) { + $this->add(new $_name); + } } /** @@ -40,15 +42,12 @@ public function clear($cache = null, $id = null) { } } - public function addCache($cache) { - foreach ($cache as $key => $_className) { - $this->_addCachelet($key, new $_className); + public function add(CacheSupportCacheletInterface $cache, $id = null) { + if ($id === null) { + $id = $cache->getId(); } - } - - protected function _addCachelet($key, CacheSupportCacheletInterface $cachelet) { - if (!isset($this->_Caches[$key])) { - $this->_Caches[$key] = $cachelet; + if (!isset($this->_Caches[$id])) { + $this->_Caches[$id] = $cache; } } @@ -58,15 +57,27 @@ interface CacheSupportCacheletInterface { public function clear($id = null); + public function getId(); + + } + + abstract class CacheSupportCachelet implements CacheSupportCacheletInterface { + + public function getId() { + return str_replace('CacheSupportCachelet', '', get_class($this)); + } + } App::uses('CakeEvent', 'Event'); App::uses('CakeEventListener', 'Event'); App::uses('CacheTree', 'Lib/CacheTree'); - class ThreadCacheSupportCachelet implements CacheSupportCacheletInterface, + class ThreadCacheSupportCachelet extends CacheSupportCachelet implements CakeEventListener { + protected $_title = 'Thread'; + protected $_CacheTree; public function __construct() { @@ -117,7 +128,9 @@ public function clear($id = null) { } - class SaitoCacheSupportCachelet implements CacheSupportCacheletInterface { + class SaitoCacheSupportCachelet extends CacheSupportCachelet { + + protected $_title = 'Saito'; public function clear($id = null) { Cache::clear(false, 'default'); @@ -126,7 +139,9 @@ public function clear($id = null) { } - class ApcCacheSupportCachelet implements CacheSupportCacheletInterface { + class ApcCacheSupportCachelet extends CacheSupportCachelet { + + protected $_title = 'Apc'; public function clear($id = null) { if (function_exists('apc_store')) { @@ -138,7 +153,9 @@ public function clear($id = null) { } - class OpCacheSupportCachelet implements CacheSupportCacheletInterface { + class OpCacheSupportCachelet extends CacheSupportCachelet { + + protected $_title = 'OpCache'; public function clear($id = null) { if (function_exists('opcache_reset')) { @@ -148,7 +165,9 @@ public function clear($id = null) { } - class CakeCacheSupportCachelet implements CacheSupportCacheletInterface { + class CakeCacheSupportCachelet extends CacheSupportCachelet { + + protected $_title = 'Cake'; public function clear($id = null) { Cache::clearGroup('persistent'); From b3c8b5879f67d5560d739cedf428c6bdc21a7154 Mon Sep 17 00:00:00 2001 From: Schlaefer Date: Sun, 10 Nov 2013 11:36:47 +0100 Subject: [PATCH 2/4] adds a `Saito.Cachelets` to Configure to add additional cachelets --- .../Component/CacheSupportComponent.php | 14 +++++++ docs/dev-namespace.md | 37 ++++++++++--------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/app/Controller/Component/CacheSupportComponent.php b/app/Controller/Component/CacheSupportComponent.php index 1b3036c5f..84745cb35 100644 --- a/app/Controller/Component/CacheSupportComponent.php +++ b/app/Controller/Component/CacheSupportComponent.php @@ -12,10 +12,24 @@ class CacheSupportComponent extends Component { public function initialize(Controller $Controller) { $this->_CacheSupport = new CacheSupport(); + $this->_addConfigureCachelets(); $this->CacheTree = CacheTree::getInstance(); $this->CacheTree->initialize($Controller); } + protected function _addConfigureCachelets() { + $_additionalCachelets = Configure::read('Saito.Cachelets'); + if (!$_additionalCachelets) { + return; + } + foreach ($_additionalCachelets as $_c) { + if (!class_exists(($_c['name']))) { + App::uses($_c['name'], $_c['location']); + } + $this->_CacheSupport->add(new $_c['name']); + } + } + public function beforeRender(Controller $Controller) { $Controller->set('CacheTree', $this->CacheTree); } diff --git a/docs/dev-namespace.md b/docs/dev-namespace.md index 377eeee0d..9ed7afd19 100644 --- a/docs/dev-namespace.md +++ b/docs/dev-namespace.md @@ -1,24 +1,25 @@ Cache ===== -Kind | Namespace | Key | Subkey | Type | Comment ------ | --------- | ---- | ------- | ---- | ------- -Cache | Saito | Settings | | | Siehe Configuration -Cache | Saito | Cache | registerGc | timestamp | timestamp of last registerGc -Cache | Saito | Cache | catForAccession | array | cache for categories for accession -Cache | Saito | Cache | appSettings | array | cache for app settings -Cache | Saito | Smilies | smilies_all | array | Smilies from `smilies` table -Configuration | Saito | Cache | Thread | bool | if true use thread cache -Configuration | Saito | useSaltForUserPasswords | | bool | unsalted md5 mode for user passwords -Configuration | Saito | markItUp | nextCssId | int | next CSS-ID for button in the markItUp-CSS -Configuration | Saito | markItUp | additionalButtons | array | Additional buttons shown in the markItUpEditor -Configuration | Saito | Settings | | array | Array with App Settings -Configuration | Saito | Slidetabs | all | array | names of all installed slidetabs -Configuration | Saito | Smilies | smilies_all | array | Smilies from `smilies` table -Configuration | Saito | Smlies | smilies_all_html | array | Html-formatierte Smilies -Configuration | Saito | theme | | string | theme name; default ist "default" -Configuration | Saito | v | | string | internal revision number -Session | User | last_refresh_tmp | | integer | Speichert letzten Session Login für Mark as Read +Kind | Namespace | Key | Subkey | Type | Comment +----- | --------- | ---- | ------- | ---- | ------- +Cache | Saito | Settings | | | Siehe Configuration +Cache | Saito | Cache | registerGc | timestamp | timestamp of last registerGc +Cache | Saito | Cache | catForAccession | array | cache for categories for accession +Cache | Saito | Cache | appSettings | array | cache for app settings +Cache | Saito | Smilies | smilies_all | array | Smilies from `smilies` table +Configuration | Saito | Cache | Thread | bool | if true use thread cache +Configuration | Saito | Cachelets | | string | +Configuration | Saito | useSaltForUserPasswords | | bool | unsalted md5 mode for user passwords +Configuration | Saito | markItUp | nextCssId | int | next CSS-ID for button in the markItUp-CSS +Configuration | Saito | markItUp | additionalButtons | array | Additional buttons shown in the markItUpEditor +Configuration | Saito | Settings | | array | Array with App Settings +Configuration | Saito | Slidetabs | all | array | names of all installed slidetabs +Configuration | Saito | Smilies | smilies_all | array | Smilies from `smilies` table +Configuration | Saito | Smlies | smilies_all_html | array | Html-formatierte Smilies +Configuration | Saito | theme | | string | theme name; default ist "default" +Configuration | Saito | v | | string | internal revision number +Session | User | last_refresh_tmp | | integer | Speichert letzten Session Login für Mark as Read Settings From 5b3254633a05d8897c2c3731f9b1a4e9df27058e Mon Sep 17 00:00:00 2001 From: Schlaefer Date: Sun, 10 Nov 2013 11:51:05 +0100 Subject: [PATCH 3/4] fixes #166 Touch mobile cache manifest on "Cache clear" button. --- app/Controller/Component/CacheSupportComponent.php | 9 +++++++++ app/Plugin/M/Config/bootstrap.php | 2 ++ app/Plugin/M/Controller/MsController.php | 3 +++ app/Plugin/M/Lib/MCacheSupportCachelet.php | 11 +++++++++++ app/Plugin/M/webroot/touch.txt | 1 + 5 files changed, 26 insertions(+) create mode 100644 app/Plugin/M/Lib/MCacheSupportCachelet.php create mode 100644 app/Plugin/M/webroot/touch.txt diff --git a/app/Controller/Component/CacheSupportComponent.php b/app/Controller/Component/CacheSupportComponent.php index 84745cb35..f4016dc05 100644 --- a/app/Controller/Component/CacheSupportComponent.php +++ b/app/Controller/Component/CacheSupportComponent.php @@ -17,6 +17,15 @@ public function initialize(Controller $Controller) { $this->CacheTree->initialize($Controller); } + /** + * Adds additional cachelets from Configure `Saito.Cachelets` + * + * E.g. use in `Plugin//Config/bootstrap.php`: + * + * + * Configure::write('Saito.Cachelets.M', ['location' => 'M.Lib', 'name' => 'MCacheSupportCachelet']); + * + */ protected function _addConfigureCachelets() { $_additionalCachelets = Configure::read('Saito.Cachelets'); if (!$_additionalCachelets) { diff --git a/app/Plugin/M/Config/bootstrap.php b/app/Plugin/M/Config/bootstrap.php index d0fa9d898..dda8646a7 100644 --- a/app/Plugin/M/Config/bootstrap.php +++ b/app/Plugin/M/Config/bootstrap.php @@ -11,3 +11,5 @@ 'scopes' => ['mobile-client'] ] ); + + Configure::write('Saito.Cachelets.M', ['location' => 'M.Lib', 'name' => 'MCacheSupportCachelet']); \ No newline at end of file diff --git a/app/Plugin/M/Controller/MsController.php b/app/Plugin/M/Controller/MsController.php index a2dd42ef7..b57cf9d4d 100644 --- a/app/Plugin/M/Controller/MsController.php +++ b/app/Plugin/M/Controller/MsController.php @@ -34,7 +34,9 @@ public function manifest() { $this->set( 'touch', + md5( Configure::read('debug') . + filemtime(App::pluginPath('M') . 'webroot/touch.txt') . filemtime(App::pluginPath('M') . 'View/Elements/custom_html_header.ctp') . filemtime(App::pluginPath('M') . 'webroot/dist/js.js') . filemtime( @@ -43,6 +45,7 @@ public function manifest() { filemtime( App::pluginPath('M') . 'webroot/dist/theme.css' ) + ) ); } diff --git a/app/Plugin/M/Lib/MCacheSupportCachelet.php b/app/Plugin/M/Lib/MCacheSupportCachelet.php new file mode 100644 index 000000000..1f1eafdde --- /dev/null +++ b/app/Plugin/M/Lib/MCacheSupportCachelet.php @@ -0,0 +1,11 @@ + Date: Sun, 10 Nov 2013 13:59:19 +0100 Subject: [PATCH 4/4] bumps version string --- app/Config/version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Config/version.php b/app/Config/version.php index be957950b..4c03f6230 100644 --- a/app/Config/version.php +++ b/app/Config/version.php @@ -1,2 +1,2 @@