From 664447a67b1f722d0c529df34b83b18755ed472c Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 21 Jan 2020 10:02:29 +0200 Subject: [PATCH] Added Flex cache configuration options --- CHANGELOG.md | 5 +- system/blueprints/config/system.yaml | 70 ++++++++++++++++++- system/blueprints/flex/shared/configure.yaml | 44 ++++++------ system/config/system.yaml | 16 ++++- system/src/Grav/Common/Page/Pages.php | 2 +- .../Service/AccountsServiceProvider.php | 8 +-- 6 files changed, 113 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c15bb8d0b..d40908d92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,12 @@ 1. [](#new) * _POTENTIAL BREAKING CHANGE:_ Upgraded Parsedown to 1.7 for Parsedown-Extra 0.8. Plugins that extend Parsedown may need a fix to render as HTML + * Added `$grav['flex']` to access all registered Flex Directories + * Added `FlexRegisterEvent` which triggers when `$grav['flex']` is being accessed the first time + * Added Flex cache configuration options * Added `PluginsLoadedEvent` which triggers after plugins have been loaded but not yet initialized * Added `SessionStartEvent` which triggers when session is started - * Added `RegisterPermissionsEvent` which triggers when `$grav['permissions']` is being accessed the first time + * Added `PermissionsRegisterEvent` which triggers when `$grav['permissions']` is being accessed the first time 1. [](#improved) * Blueprint validation: Added `validate: value_type: bool|int|float|string|trim` to `array` to filter all the values inside the array 1. [](#bugfix) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index 308e26fe2..0c526774e 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -1472,22 +1472,30 @@ form: title: PLUGIN_ADMIN.EXPERIMENTAL underline: true + flex_pages: + type: section + title: Flex Pages + pages.type: type: select label: PLUGIN_ADMIN.PAGES_TYPE highlight: stable help: PLUGIN_ADMIN.PAGES_TYPE_HELP options: - page: PLUGIN_ADMIN.REGULAR + regular: PLUGIN_ADMIN.REGULAR flex: PLUGIN_ADMIN.FLEX + flex_accounts: + type: section + title: Flex Accounts + accounts.type: type: select label: PLUGIN_ADMIN.ACCOUNTS_TYPE highlight: stable help: PLUGIN_ADMIN.ACCOUNTS_TYPE_HELP options: - data: PLUGIN_ADMIN.REGULAR + regular: PLUGIN_ADMIN.REGULAR flex: PLUGIN_ADMIN.FLEX accounts.storage: @@ -1498,3 +1506,61 @@ form: options: file: PLUGIN_ADMIN.FILE folder: PLUGIN_ADMIN.FOLDER + + flex_caching: + type: section + title: PLUGIN_ADMIN.FLEX_CACHING + + flex.cache.index.enabled: + type: toggle + label: PLUGIN_ADMIN.FLEX_INDEX_CACHE_ENABLED + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + flex.cache.index.lifetime: + type: text + label: PLUGIN_ADMIN.FLEX_INDEX_CACHE_LIFETIME + default: 60 + validate: + type: int + + flex.cache.object.enabled: + type: toggle + label: PLUGIN_ADMIN.FLEX_OBJECT_CACHE_ENABLED + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + flex.cache.object.lifetime: + type: text + label: PLUGIN_ADMIN.FLEX_OBJECT_CACHE_LIFETIME + default: 600 + validate: + type: int + + flex.cache.render.enabled: + type: toggle + label: PLUGIN_ADMIN.FLEX_RENDER_CACHE_ENABLED + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + flex.cache.render.lifetime: + type: text + label: PLUGIN_ADMIN.FLEX_RENDER_CACHE_LIFETIME + default: 600 + validate: + type: int diff --git a/system/blueprints/flex/shared/configure.yaml b/system/blueprints/flex/shared/configure.yaml index 30fe52887..158fc5f61 100644 --- a/system/blueprints/flex/shared/configure.yaml +++ b/system/blueprints/flex/shared/configure.yaml @@ -5,66 +5,66 @@ form: plugin_tabs: type: tabs fields: - cache_tab: + cache: type: tab title: Caching fields: object.cache.index.enabled: type: toggle toggleable: true - label: Enable Index Caching + label: PLUGIN_ADMIN.FLEX_INDEX_CACHE_ENABLED highlight: 1 - config-default@: plugins.flex-objects.object.cache.index.enabled + config-default@: system.flex.cache.index.enabled options: - 1: Enabled - 0: Disabled + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED validate: type: bool - object.cache.index.timeout: + object.cache.index.lifetime: type: text toggleable: true - label: Index Cache Timeout (s) - config-default@: plugins.flex-objects.object.cache.index.timeout + label: PLUGIN_ADMIN.FLEX_INDEX_CACHE_LIFETIME + config-default@: system.flex.cache.index.lifetime validate: type: int object.cache.object.enabled: type: toggle toggleable: true - label: Enable Object Caching + label: PLUGIN_ADMIN.FLEX_OBJECT_CACHE_ENABLED highlight: 1 - config-default@: plugins.flex-objects.object.cache.object.enabled + config-default@: system.flex.cache.object.enabled options: - 1: Enabled - 0: Disabled + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED validate: type: bool - object.cache.object.timeout: + object.cache.object.lifetime: type: text toggleable: true - label: Object Cache Timeout (s) - config-default@: plugins.flex-objects.object.cache.object.timeout + label: PLUGIN_ADMIN.FLEX_OBJECT_CACHE_LIFETIME + config-default@: system.flex.cache.object.lifetime validate: type: int object.cache.render.enabled: type: toggle toggleable: true - label: Enable Render Caching + label: PLUGIN_ADMIN.FLEX_RENDER_CACHE_ENABLED highlight: 1 - config-default@: plugins.flex-objects.object.cache.render.enabled + config-default@: system.flex.cache.render.enabled options: - 1: Enabled - 0: Disabled + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED validate: type: bool - object.cache.render.timeout: + object.cache.render.lifetime: type: text toggleable: true - label: Render Cache Timeout (s) - config-default@: plugins.flex-objects.object.cache.render.timeout + label: PLUGIN_ADMIN.FLEX_RENDER_CACHE_LIFETIME + config-default@: system.flex.cache.render.lifetime validate: type: int diff --git a/system/config/system.yaml b/system/config/system.yaml index f21b96721..6721d573e 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -28,7 +28,7 @@ home: hide_in_urls: false # Hide the home route in URLs pages: - type: page # EXPERIMENTAL: Page type: page or flex + type: regular # EXPERIMENTAL: Page type: regular or flex theme: quark # Default theme (defaults to "quark" theme) order: by: default # Order pages by "default", "alpha" or "date" @@ -165,9 +165,21 @@ gpm: official_gpm_only: true # By default GPM direct-install will only allow URLs via the official GPM proxy to ensure security accounts: - type: data # EXPERIMENTAL: Account type: data or flex + type: regular # EXPERIMENTAL: Account type: regular or flex storage: file # EXPERIMENTAL: Flex storage type: file or folder +flex: + cache: + index: + enabled: true # Set to true to enable Flex index caching. Is used to cache timestamps in files + lifetime: 60 # Lifetime of cached index in seconds (0 = infinite) + object: + enabled: true # Set to true to enable Flex object caching. Is used to cache object data + lifetime: 600 # Lifetime of cached objects in seconds (0 = infinite) + render: + enabled: true # Set to true to enable Flex render caching. Is used to cache rendered output + lifetime: 600 # Lifetime of cached HTML in seconds (0 = infinite) + strict_mode: yaml_compat: true # Grav 1.5+: Enables YAML backwards compatibility twig_compat: true # Grav 1.5+: Enables deprecated Twig autoescape setting (autoescape: false) diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 8bd5cf798..58c3ae205 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -1991,7 +1991,7 @@ class Pages */ protected function getVersion() { - return $this->directory ? 'flex' : 'page'; + return $this->directory ? 'flex' : 'regular'; } /** diff --git a/system/src/Grav/Common/Service/AccountsServiceProvider.php b/system/src/Grav/Common/Service/AccountsServiceProvider.php index 9167bd3f3..bf75dd5c2 100644 --- a/system/src/Grav/Common/Service/AccountsServiceProvider.php +++ b/system/src/Grav/Common/Service/AccountsServiceProvider.php @@ -52,7 +52,7 @@ class AccountsServiceProvider implements ServiceProviderInterface $container['accounts'] = function (Container $container) { $type = $this->initialize($container); - return $type === 'flex' ? $this->flexAccounts($container) : $this->dataAccounts($container); + return $type === 'flex' ? $this->flexAccounts($container) : $this->regularAccounts($container); }; $container['user_groups'] = static function () { @@ -69,7 +69,7 @@ class AccountsServiceProvider implements ServiceProviderInterface protected function initialize(Container $container): string { $isDefined = defined('GRAV_USER_INSTANCE'); - $type = strtolower($isDefined ? GRAV_USER_INSTANCE : $container['config']->get('system.accounts.type', 'data')); + $type = strtolower($isDefined ? GRAV_USER_INSTANCE : $container['config']->get('system.accounts.type', 'regular')); if ($type === 'flex') { if (!$isDefined) { @@ -110,13 +110,13 @@ class AccountsServiceProvider implements ServiceProviderInterface 100000 ); } elseif (!$isDefined) { - define('GRAV_USER_INSTANCE', 'DATA'); + define('GRAV_USER_INSTANCE', 'REGULAR'); } return $type; } - protected function dataAccounts(Container $container) + protected function regularAccounts(Container $container) { // Use User class for backwards compatibility. return new DataUser\UserCollection(User::class);