From dd56737fdd5a8f68f9d1d08f2b9d46f6166e61cf Mon Sep 17 00:00:00 2001 From: watura Date: Thu, 20 Feb 2020 15:03:17 +0900 Subject: [PATCH 1/6] feat: add endpoint for invalidate cache --- Controller/PagesController.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Controller/PagesController.php b/Controller/PagesController.php index 8be6ac3..68ad7c0 100644 --- a/Controller/PagesController.php +++ b/Controller/PagesController.php @@ -13,6 +13,8 @@ App::uses('Space', 'Rooms.Model'); App::uses('NetCommonsUrl', 'NetCommons.Utility'); App::uses('CurrentLibPage', 'NetCommons.Lib/Current'); +App::uses('NetCommonsCache', 'NetCommons.Utility'); +App::uses('NetCommonsCDNCache', 'NetCommons.Utility'); /** * ページ表示 Controller @@ -22,6 +24,12 @@ * @package NetCommons\Pages\Controller */ class PagesController extends PagesAppController { +/** + * 高頻度なキャッシュ無効化を防ぐために、無効化のリクエストを無視する期間(秒) + * + * @var float + */ + const NO_CACHE_INVALIDATION_DURATION_SEC = 1.0; /** * 使用するModels @@ -52,6 +60,7 @@ class PagesController extends PagesAppController { * @return void */ public function beforeFilter() { + $this->Auth->allow('clear'); //CurrentPage::__getPageConditionsでページ表示として扱う if ($this->params['action'] === 'index') { $this->request->params['pageView'] = true; @@ -120,4 +129,21 @@ public function change_setting_mode() { $this->redirect($redirectUrl); } +/** + * CDN Cache を削除する + * + * @return void + */ + public function clear() { + $ncCache = new NetCommonsCache('cache_invalidated_at', false, 'netcommons_core'); + $lastTime = floatval($ncCache->read()); + $now = microtime(true); + if ($now - $lastTime > self::NO_CACHE_INVALIDATION_DURATION_SEC) { + $ncCache->write($now); + $cdnCache = new NetCommonsCDNCache(); + $cdnCache->invalidate(); + } + $this->redirect('/'); + } + } From f1ea2146c294d2476ddcfb1e14c2f677d8c08948 Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Fri, 21 Feb 2020 18:41:51 +0900 Subject: [PATCH 2/6] feat: updateTokens in the case where cache can be used --- View/Layouts/default.ctp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/View/Layouts/default.ctp b/View/Layouts/default.ctp index 6c12c2e..1647b2d 100644 --- a/View/Layouts/default.ctp +++ b/View/Layouts/default.ctp @@ -19,6 +19,9 @@ if (AuthComponent::user()) { } else { $bodyCss .= ' body-nologgedin'; } + +$nonCached = $this->response->header()['Pragma'] === 'no-cache' || + strncmp('origin-', $_SERVER['SERVER_NAME'], 7) !== 0; ?> @@ -48,7 +51,9 @@ if (AuthComponent::user()) { element('NetCommons.common_header'); ?> -
+
+
From a4c11fff20b6c02a27b5a362016c3dc4c7a0a082 Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Sun, 1 Mar 2020 11:57:27 +0900 Subject: [PATCH 3/6] refactor: use CDNCacheHelper --- Controller/PagesController.php | 21 ++++++--------------- View/Layouts/default.ctp | 5 +---- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/Controller/PagesController.php b/Controller/PagesController.php index 68ad7c0..ce069b8 100644 --- a/Controller/PagesController.php +++ b/Controller/PagesController.php @@ -5,6 +5,8 @@ * @copyright Copyright 2014, NetCommons Project * @author Kohei Teraguchi * @author Shohei Nakajima + * @author Wataru Nishimoto + * @author Kazunori Sakamoto * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License */ @@ -13,7 +15,6 @@ App::uses('Space', 'Rooms.Model'); App::uses('NetCommonsUrl', 'NetCommons.Utility'); App::uses('CurrentLibPage', 'NetCommons.Lib/Current'); -App::uses('NetCommonsCache', 'NetCommons.Utility'); App::uses('NetCommonsCDNCache', 'NetCommons.Utility'); /** @@ -21,15 +22,11 @@ * * @author Kohei Teraguchi * @author Shohei Nakajima + * @author Wataru Nishimoto + * @author Kazunori Sakamoto * @package NetCommons\Pages\Controller */ class PagesController extends PagesAppController { -/** - * 高頻度なキャッシュ無効化を防ぐために、無効化のリクエストを無視する期間(秒) - * - * @var float - */ - const NO_CACHE_INVALIDATION_DURATION_SEC = 1.0; /** * 使用するModels @@ -135,14 +132,8 @@ public function change_setting_mode() { * @return void */ public function clear() { - $ncCache = new NetCommonsCache('cache_invalidated_at', false, 'netcommons_core'); - $lastTime = floatval($ncCache->read()); - $now = microtime(true); - if ($now - $lastTime > self::NO_CACHE_INVALIDATION_DURATION_SEC) { - $ncCache->write($now); - $cdnCache = new NetCommonsCDNCache(); - $cdnCache->invalidate(); - } + $cdnCache = new NetCommonsCDNCache(); + $cdnCache->invalidate(); $this->redirect('/'); } diff --git a/View/Layouts/default.ctp b/View/Layouts/default.ctp index 1647b2d..cea1223 100644 --- a/View/Layouts/default.ctp +++ b/View/Layouts/default.ctp @@ -19,9 +19,6 @@ if (AuthComponent::user()) { } else { $bodyCss .= ' body-nologgedin'; } - -$nonCached = $this->response->header()['Pragma'] === 'no-cache' || - strncmp('origin-', $_SERVER['SERVER_NAME'], 7) !== 0; ?> @@ -52,7 +49,7 @@ $nonCached = $this->response->header()['Pragma'] === 'no-cache' || element('NetCommons.common_header'); ?>
+ CDNCache->isCacheable() ? 'updateTokens();' : ''; ?>"> From e4b312dd20d704b4f8258d1711218103307d25a7 Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Thu, 19 Mar 2020 02:09:54 +0900 Subject: [PATCH 4/6] feat: update all like counts as well as csrf tokens --- View/Layouts/default.ctp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/View/Layouts/default.ctp b/View/Layouts/default.ctp index cea1223..cab4cb5 100644 --- a/View/Layouts/default.ctp +++ b/View/Layouts/default.ctp @@ -4,6 +4,7 @@ * * @author Noriko Arai * @author Shohei Nakajima + * @author Kazunori Sakamoto * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -49,7 +50,7 @@ if (AuthComponent::user()) { element('NetCommons.common_header'); ?>
+ CDNCache->isCacheable() ? 'updateTokens();' : ''; ?> updateLikes();"> From 031f40bc21d27904e4418e3fe34f07bbee111343 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Mon, 1 Mar 2021 17:26:51 +0900 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20test:=20travis=E3=81=AE=E3=83=96?= =?UTF-8?q?=E3=83=A9=E3=83=B3=E3=83=81=E3=82=92availability=E3=81=AB?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 555efd9..f0e0860 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ dist: trusty env: matrix: - - NETCOMMONS_VERSION=master DB=mysql + - NETCOMMONS_VERSION=availability DB=mysql global: - secure: "iq/xEV3mq8MBLWnumo8LOSc9cVvkrh7E+joO8ZpmZ7+CxfpFW1ESp2X552ncso9LPMH2rl24/ZR24xwwklNxpqxu+erXfmIpiO2gCa7ESFAJW3J/irN5uRL+t7Z9RWZwFq88p4jsR+2LHeVzl+jgqVNmCpjVJd40uR1DDYzODO4=" - GIT_COMMITTER_NAME=s-nakajima From dff9d19d0ee96b35fea6b1ed63941de3b7a00dbf Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Fri, 22 Apr 2022 23:54:26 +0900 Subject: [PATCH 6/6] =?UTF-8?q?test:=20github=20actions=E3=81=AE=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9501566..d6b4be4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -38,7 +38,7 @@ jobs: NC3_BUILD_DIR: "/opt/nc3" NC3_DOCKER_DIR: "/opt/docker" NC3_GIT_URL: "git://github.com/NetCommons3/NetCommons3.git" - NC3_GIT_BRANCH: "master" + NC3_GIT_BRANCH: "availability" PLUGIN_BUILD_DIR: ${{ github.workspace }} PHP_VERSION: ${{ matrix.php }} MYSQL_VERSION: ${{ matrix.mysql }}