install plugin

This commit is contained in:
2020-09-08 14:40:03 +02:00
parent 29a83739f4
commit c471d6ad2b
286 changed files with 24316 additions and 7 deletions
@@ -0,0 +1,53 @@
# v3.0.2
## 06/21/2020
1. [](#improved)
* fix default value for per_user_caching in admin [#18](https://github.com/getgrav/grav-plugin-advanced-pagecache/pull/18)
# v3.0.1
## 06/21/2020
1. [](#bugfix)
* Check for user when login plugin is not installed [#19](https://github.com/getgrav/grav-plugin-advanced-pagecache/issues/19)
# v3.0.0
## 06/08/2020
1. [](#new)
* Allow disabling user on login [#17](https://github.com/getgrav/grav-plugin-advanced-pagecache/issues/17)
1. [](#improved)
* Fixed conflicting and misleading messages [#16](https://github.com/getgrav/grav-plugin-advanced-pagecache/issues/16)
# v2.0.0
## 04/27/2019
1. [](#new)
* Advanced page cache now works with language prefixes
1. [](#improved)
* Switch to a disable toggles for `querystrings` and `params`. Default is now to **not cache** these.
* Blacklist and Whitelist now work with extensions
* Optimized code to be more efficient
# v1.2.0
## 07/14/2016
1. [](#bugfix)
* Fix issue with URLs with extension being considered like the default page extension [#10](https://github.com/getgrav/grav-plugin-advanced-pagecache/issues/10)
# v1.1.1
## 09/02/2015
1. [](#improved)
* Switched to `value_only` arrays for whitelist and blacklist
# v1.1.0
## 08/25/2015
1. [](#improved)
* Added blueprints for Grav Admin plugin
# v1.0.0
## 06/16/2015
1. [](#new)
* ChangeLog started...
+22
View File
@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2014 Grav
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+56
View File
@@ -0,0 +1,56 @@
# Grav AdvancedPageCache Plugin
`AdvancedPageCache` is a powerful static page cache type plugin that caches the entire page output to the Grav cache and reuses this when the URL path is requested again. This can dramatically increase the performance of a Grav site. Due to the static nature of this cache, if enabled, you will need to **manually** clear the cache if you make any page modifications. This cache plugin (by default) will not cache pages that have URLs that contain either **querystring or grav-paramater** style values, you may want to disable this behavior.
This plugin can provide dramatic performance boosts and is an ideal solution for sites with many pages and predominantly static content.
| NOTE: Grav Debugger will not display when the page is cached
# Installation
Installing the AdvancedPageCache plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.
## GPM Installation (Preferred)
The simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's Terminal (also called the command line). From the root of your Grav install type:
bin/gpm install advanced-pagecache
This will install the AdvancedPageCache plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/advanced-pagecache`.
## Manual Installation
To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `advanced-pagecache`. You can find these files either on [GitHub](https://github.com/getgrav/grav-plugin-precache) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras).
You should now have all the plugin files under
/your/site/grav/user/plugins/advanced-pagecache
# Usage
The default configuration provided in the `user/plugins/advanced-pagecache.yaml` file contains sensible defaults:
```
enabled: true # set to false to disable this plugin completely
disabled_with_params: true # disabled if there are params set on this URI (eg. /color:blue)
disabled_with_query: true # disabled if there are query options set on this URI (eg. ?color=blue)
disabled_on_login: true # disabled if a user is logged in on the frontend of the site
per_user_caching: false # enable per-user caching of pages (if not disabled_on_login)
disabled_extensions: [rss,xml,json] # disabled for these extensions
whitelist: # set to array of enabled page paths to enable only when in whitelist
- /cache-this-page
blacklist: # set to array and provide list of page paths to disable plugin for
- /error
- /login
- /random
- /dont-cache-this-page
```
If a **whitelist** array is provided, **only** pages specifically listed will be cached. Language prefixes are ignored, but URL extensions are taken into account.
If a **blacklist** array is provided, this plugin will cache all pages except those specifically listed. Language prefixes are ignored, but URL extensions are taken into account.
## Important Notes
This plugin is intended for **production** scenarios where optimal performance is desired and more important than convenience. `AdvancedPageCache` is not intended to be used in a development environment or a rapidly changing one.
Many plugin events will not fire when a cached page is found because these are not processed by Grav, only the static page is returned. For example, because there is no RenderEvent with the cached page, the DebugBar will not show even if enabled.
@@ -0,0 +1,103 @@
<?php
namespace Grav\Plugin;
use \Grav\Common\Plugin;
use \Grav\Common\Uri;
use Grav\Common\User\DataUser\User;
class AdvancedPageCachePlugin extends Plugin
{
/** @var Config $config */
protected $config;
protected $pagecache_key;
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0]
];
}
/**
* Return `true` if the page has no extension, or has the default page extension.
* Return `false` if for example is a RSS version of the page
*/
private function isValidExtension() {
/** @var Uri $uri */
$uri = $this->grav['uri'];
$extension = $uri->extension();
if (!$extension) {
return true;
}
$disabled_extensions = $this->grav['config']->get('plugins.advanced-pagecache.disabled_extensions');
if (in_array($extension, (array) $disabled_extensions)) {
return false;
}
return true;
}
/**
* Initialize configuration
*/
public function onPluginsInitialized()
{
$config = $this->grav['config']->get('plugins.advanced-pagecache');
/** @var Uri $uri */
$uri = $this->grav['uri'];
$full_route = $uri->uri();
$route = str_replace($uri->baseIncludingLanguage(), '', $full_route);
$params = $uri->params(null, true);
$query = $uri->query(null, true);
$user = $this->grav['user'] ?? new User();
$lang = $this->grav['language']->getLanguageURLPrefix();
// Definitely don't run in admin plugin or is not a valid extension
if ($this->isAdmin() || !$this->isValidExtension()) {
return;
}
// If this url is not whitelisted try some other tests
if (!in_array($route, (array)$config['whitelist'])) {
// do not run in these scenarios
if ($config['disabled_with_params'] && !empty($params) ||
$config['disabled_with_query'] && !empty($query) ||
$config['disabled_on_login'] && $user["authenticated"] ||
in_array($route, (array)$config['blacklist'])) {
return;
}
}
if ($config['per_user_caching']) {
$this->pagecache_key = md5('adv-pc-' . $lang . $full_route . $user["username"]);
} else {
$this->pagecache_key = md5('adv-pc-' . $lang . $full_route);
}
// Should run and store page
$this->enable([
'onOutputGenerated' => ['onOutputGenerated', 0]
]);
$pagecache = $this->grav['cache']->fetch($this->pagecache_key);
if ($pagecache) {
echo $pagecache;
exit;
}
}
/**
* Save the page to the cache
*/
public function onOutputGenerated()
{
$this->grav['cache']->save($this->pagecache_key, $this->grav->output);
}
}
@@ -0,0 +1,13 @@
enabled: true # set to false to disable this plugin completely
disabled_with_params: true # disabled if there are params set on this URI (eg. /color:blue)
disabled_with_query: true # disabled if there are query options set on this URI (eg. ?color=blue)
disabled_on_login: true # disabled if a user is logged in on the frontend of the site
per_user_caching: false # enable per-user caching of pages (if not disabled_on_login)
disabled_extensions: [rss,xml,json] # disabled for these extensions
whitelist: # set to array of enabled page paths to enable only when in whitelist
- /cache-this-page
blacklist: # set to array and provide list of page paths to disable plugin for
- /error
- /login
- /random
- /dont-cache-this-page
@@ -0,0 +1,103 @@
name: AdvancedPageCache
slug: advanced-pagecache
type: plugin
version: 3.0.2
description: "AdvancedPageCache turbo charges your site by statically caching pages."
icon: dashboard
author:
name: Team Grav
email: devs@getgrav.org
url: http://getgrav.org
homepage: https://github.com/getgrav/grav-plugin-advanced-pagecache
keywords: "static, cache, plugin, performance"
bugs: https://github.com/getgrav/grav-plugin-advanced-pagecache/issues
license: MIT
form:
validation: strict
fields:
enabled:
type: toggle
label: Plugin Status
highlight: 1
default: 1
options:
1: Enabled
0: Disabled
validate:
type: bool
disabled_with_params:
type: toggle
label: Disabled with Params
highlight: 1
default: 1
options:
1: Enabled
0: Disabled
validate:
type: bool
help: Disable caching if there are params set on the URI (eg. /color:blue)
disabled_with_query:
type: toggle
label: Disabled with Query
highlight: 1
default: 1
options:
1: Enabled
0: Disabled
validate:
type: bool
help: Disable caching if there are query options set on the URI (eg. ?color=blue)
disabled_on_login:
type: toggle
label: Disabled for logged in users
highlight: 1
default: 1
options:
1: Enabled
0: Disabled
validate:
type: bool
help: Disable caching if the user is logged in
per_user_caching:
type: toggle
label: Per-user caching
highlight: 0
default: 0
options:
1: Enabled
0: Disabled
validate:
type: bool
help: Enable per-user caching for logged in users (if caching is not disabled for logged in users)
disabled_extensions:
type: selectize
size: large
placeholder: "e.g. rss, xml, json"
label: Disabled Extensions
help: URL extensions that should not be cached (e.g. for news feeds)
classes: fancy
validate:
type: commalist
whitelist:
type: array
value_only: true
label: Whitelist
help: "Enable the plugin on these page paths regardless of other configuration options (don't include prefix, but do include extension)"
placeholder_key:
placeholder_value: /cache-this-route
blacklist:
type: array
value_only: true
label: Blacklist
help: "Disable the plugin when calling these page paths (don't include language prefix, but do include extension)"
placeholder_key:
placeholder_value: /dont-cache-this-route