Remove cacheroute plugin, breaks live instance (#347)

We've had it deleted locally on the live instance for a while, but it would be better
to make the Git version match what we do use in production.
This commit is contained in:
Rémi Verschelde
2021-08-16 04:33:54 +02:00
committed by GitHub
parent d860be612c
commit e1442c2e6c
23 changed files with 0 additions and 550 deletions

View File

@@ -48,7 +48,6 @@ jobs:
env -C plugins/paulvonzimmerman/patreon composer install
php artisan plugin:refresh pikanji.agent
php artisan plugin:refresh rainlab.blog
php artisan plugin:refresh serenitynow.cacheroute
php artisan plugin:refresh sobored.rss
- name: Run Lighthouse CI

View File

@@ -1,14 +0,0 @@
<?php namespace SerenityNow\Cacheroute;
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
public function boot()
{
//add RouteCacheMiddleware as a global middleware to intercept all routes
$this->app['Illuminate\Contracts\Http\Kernel']
->pushMiddleware('SerenityNow\CacheRoute\Classes\RouteCacheMiddleware');
}
}

View File

@@ -1,45 +0,0 @@
##CacheRoute plugin
As we are well aware, the best way to speed up a web application is to serve cached content. This is especially true for
an interpreted language like PHP.The logic is simple - if there is no server-side processing to render a page, response is almost immediate.
The CacheRoute plugin for OctoberCMS is designed to provide a speedup to relatively static pages by caching entire routes.
So, Let's say you indicate in the backend that you want to have "`blog/*`" cached. The first time you invoke a url matching this pattern,
(i.e. cache miss) it goes through all the motions of querying the database, rendering the template and displaying the output.
This entire page content is then cached (in whatever store you specify in your `config->cache` file).
The next time the same url is requested (while the number of minutes specified in the TTL does not elapse),
the cached content is served. So, no database calls, no php rendering overhead, no twig rendering overhead etc.
This results in substantial page speedup.
###How it works
Routes (or route patterns) that you want cached are entered in the backend section (CacheRoutes).
On boot, the CacheRoute plugin registers a global middleware that intercepts all requests. This middleware then
uses "before" and "after" criteria to cache entire pages that match pattern(s) specified in the table.
###Main features
* The contents of the backend cacheroute table are cached to avoid the overhead of a database query on every route - The ttl for
this cache is extracted from `config->cms->urlCacheTtl` (i.e. `Config::get(cms.urlCacheTtl)`)
* You can specify different TTL (time to live) values for different routes
* The plugin uses a simple `Request::is('pattern')` to check for a match (and cache the corresponding route)
###Installation
1. Go to __Settings > "Updates & Plugins"__ page in the Backend.
2. Click on the __"Install plugins"__ option.
3. Type __CacheRoute__ text in the search field, and pick the appropriate plugin.
4. On your backend, under the "CacheRoute" menu, enter your route pattern(s) and corresponding cache ttl and sort order.
5. Example:
| Route Pattern | TTL | Sort Order |
|-----------------|---------------|-------------|
| resume | 100 | 1 |
| blog | 10 | 2 |
| blog/* | 10 | 3 |
###Usage Notes and other information
* Be mindful of what you are caching! This approach works best for relatively static global content.
* Note that __it is required to clear ALL cached content every time you add a new route pattern for the plugin to work with it__. To do this, you can use the provided button in the plugin backend panel (or "`php artisan cache:clear`" on terminal). This will clear __ALL__ the cached content, both by the plugin and the backend, if any.
* You can verify functionality by appending "`?cache-info`" (or "`?debug`" as in previous versions of this plugin) to a cached url, e.g.: `http://mysite.com/mypage?cache-info`.
This would show a modal window (centered in the lower part of the screen) over your page content reflecting this specific cache related information, as well as a button to clear (__only__) this specific content cache.
* You can also clear any specific page cached content directly appending "`?cache-clear`" to its url, e.g.: `http://mysite.com/mypage?cache-clear`
* FYI: the cache key is a slug of the request url (without any get params) i.e. str_slug($request->url())

View File

@@ -1,112 +0,0 @@
<?php
namespace SerenityNow\Cacheroute\Classes;
use Illuminate\Http\Request as LaravelRequest;
use SerenityNow\Cacheroute\Models\CacheRoute;
use Closure;
class RouteCacheMiddleware
{
public function handle(LaravelRequest $request, Closure $next)
{
//bail if table does not exist or
//route not in the list of routes to be cached
$hasTable = \Schema::hasTable('serenitynow_cacheroute_routes');
$cacheRow = $this->shouldBeCached($request);
$ajaxRequest = $request->ajax();
if (!$hasTable || !$cacheRow || $ajaxRequest) {
return $next($request);
}
return $this->cacheResponse($request, $next, $cacheRow['cache_ttl']);
}
/**
* @param LaravelRequest $request
* @param Closure $next
* @param $ttl
* @return mixed
*/
protected function cacheResponse(LaravelRequest $request, Closure $next, $ttl)
{
$cacheKey = $this->getCacheKey($request->url());
if (\Cache::has($cacheKey)) {
return \Response::make($this->getCachedContent($cacheKey, $request, \Cache::get($cacheKey)), 200);
}
$response = $next($request);
\Cache::put($cacheKey, $response->getContent(), $ttl);
return $response;
}
/**
* add instrumentation to help with debug. Adding ?debug
* to a cached url will precede the content with "CACHED"
*
* @param $cacheKey
* @param $request
* @param $content
* @return string
*/
protected function getCachedContent($cacheKey, $request, $content)
{
$isDebugRequest = $request->exists('debug') || $request->exists('cache-info');
if ($isDebugRequest) {
return $content.'
<div class="cache-notice" style="display: block; position: fixed; width: 50%; background: #fff; padding: 20px 30px 25px; left: 50%; border: 1px solid #aaa; margin-left: calc(-50% / 2); bottom: 10%; z-index: 500; box-shadow: 0 0 20px rgba(0,0,0,0.2); font-size: 16px; font-size: 1.6rem;">
<div class="title" style="margin: -20px -30px 10px; background: #999; color: #fff; padding: 10px 30px; text-align: center;">CACHED CONTENT</div>
<span class="cache_key" style="display: inline-block; width: 100%; background: #fff; padding: 10px 10px 10px 0; margin-bottom: -10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<span class="title" style="float: left; width:45px; color: #000; font-weight: bold; line-height: 30px;">URL: </span>
<input readonly class="value" style="float: left; width: calc(100% - 45px); border:1px solid #000; color: red; padding: 5px 7px; height: 30px; background: #eee" type="text" value="'.$request->url().'">
</span>
<span class="cache_key" style="display: inline-block; width: 100%; background: #fff; color: red; padding: 10px 10px 10px 0; margin-bottom: -10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<span class="title" style="float: left; width:45px; color: #000; font-weight: bold; line-height: 30px;">KEY: </span>
<input readonly class="value" style="float: left; width: calc(100% - 45px); border:1px solid #000; color: red; padding: 5px 7px; height: 30px; background: #eee" type="text" value="'.$cacheKey.'">
</span>
<hr style="border:none;">
<a href="'.$request->url().'" class="cancel" style="float: left; background: #aaa; color: #fff; padding: 10px 15px; margin-top: 20px; text-decoration: none;">Cancel</a>
<a href="?cache-clear" class="alert alert-info" style="float: right; background: #1991d1; color: #fff; padding: 10px 15px; margin-top: 20px; text-decoration: none;">Clear this now</a>
</div>';
}
if ($request->exists('cache-clear')) {
\Cache::forget($cacheKey);
return \Redirect::to($request->url());
}
return $content;
}
//generate a cache key based on the url
/**
* @param $url
* @return string
*/
protected function getCacheKey($url)
{
return 'SerenityNow.Cacheroute.' . str_slug($url);
}
/**
* @param $request
* @return bool
*/
protected function shouldBeCached($request)
{
$cacheRouteRows = \Cache::remember('SerenityNow.Cacheroute.AllCachedRoutes',
\Config::get('cms.urlCacheTtl'),
function () {
return CacheRoute::orderBy('sort_order')->get()->toArray();
}
);
foreach ($cacheRouteRows as $cacheRow) {
if (count($cacheRow) && $request->is($cacheRow['route_pattern'])) {
return $cacheRow;
}
}
return false;
}
}

View File

@@ -1,42 +0,0 @@
<?php namespace SerenityNow\Cacheroute\Controllers;
use Backend\Classes\Controller;
use BackendMenu;
use Artisan;
use Flash;
class CacheRoutes extends Controller
{
public $implement = [
'Backend\Behaviors\ListController',
'Backend\Behaviors\FormController',
'Backend\Behaviors\ReorderController'
];
public $listConfig = 'config_list.yaml';
public $formConfig = 'config_form.yaml';
public $reorderConfig = 'config_reorder.yaml';
public $requiredPermissions = [
'serenitynow.cacheroute.manage_cacheroute'
];
/**
* CacheRoutes constructor.
*/
public function __construct()
{
parent::__construct();
BackendMenu::setContext('SerenityNow.Cacheroute', 'CacheRoute');
}
/**
*
*/
public function onClear()
{
Artisan::call('cache:clear');
Flash::success('ALL cached content cleared');
}
}

View File

@@ -1,25 +0,0 @@
<div data-control="toolbar">
<a href="<?= Backend::url('serenitynow/cacheroute/cacheroutes/create') ?>" class="btn btn-primary oc-icon-plus"><?= e(trans('backend::lang.form.create')) ?></a>
<a href="<?= Backend::url('serenitynow/cacheroute/cacheroutes/reorder') ?>" class="btn btn-primary oc-icon-sitemap"><?= e(trans('backend::lang.reorder.default_title')) ?></a>
<button
class="btn btn-default oc-icon-trash-o"
disabled="disabled"
onclick="$(this).data('request-data', {
checked: $('.control-list').listWidget('getChecked')
})"
data-request="onDelete"
data-request-confirm="<?= e(trans('backend::lang.list.delete_selected_confirm')) ?>"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger-condition="checked"
data-request-success="$(this).prop('disabled', true)"
data-stripe-load-indicator>
<?= e(trans('backend::lang.list.delete_selected')) ?>
</button>
<button
class="btn btn-warning oc-icon-trash-o"
data-request="onClear"
data-stripe-load-indicator>
Clear ALL cached content
</button>
</div>

View File

@@ -1,3 +0,0 @@
<div data-control="toolbar">
<a href="<?= Backend::url('serenitynow/cacheroute/cacheroutes') ?>" class="btn btn-primary oc-icon-caret-left"><?= e(trans('backend::lang.form.return_to_list')) ?></a>
</div>

View File

@@ -1,11 +0,0 @@
name: CacheRoutes
modelClass: SerenityNow\Cacheroute\Models\CacheRoute
form: $/serenitynow/cacheroute/models/cacheroute/fields.yaml
defaultRedirect: serenitynow/cacheroute/cacheroutes
create:
redirect: 'serenitynow/cacheroute/cacheroutes/update/:id'
redirectClose: serenitynow/cacheroute/cacheroutes
update:
redirect: serenitynow/cacheroute/cacheroutes
redirectClose: serenitynow/cacheroute/cacheroutes
preview: { }

View File

@@ -1,14 +0,0 @@
title: CacheRoutes
modelClass: SerenityNow\Cacheroute\Models\CacheRoute
list: $/serenitynow/cacheroute/models/cacheroute/columns.yaml
recordUrl: 'serenitynow/cacheroute/cacheroutes/update/:id'
noRecordsMessage: 'backend::lang.list.no_records'
showSetup: true
showCheckboxes: true
defaultSort:
column: sort_order
direction: asc
toolbar:
buttons: list_toolbar
search:
prompt: 'backend::lang.list.search_prompt'

View File

@@ -1,5 +0,0 @@
title: CacheRoutes
modelClass: SerenityNow\Cacheroute\Models\CacheRoute
nameFrom: route_pattern
toolbar:
buttons: reorder_toolbar

View File

@@ -1,46 +0,0 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('serenitynow/cacheroute/cacheroutes') ?>">CacheRoutes</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?php if (!$this->fatalError): ?>
<?= Form::open(['class' => 'layout']) ?>
<div class="layout-row">
<?= $this->formRender() ?>
</div>
<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-primary">
<?= e(trans('backend::lang.form.create')) ?>
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-default">
<?= e(trans('backend::lang.form.create_and_close')) ?>
</button>
<span class="btn-text">
<?= e(trans('backend::lang.form.or')) ?> <a href="<?= Backend::url('serenitynow/cacheroute/cacheroutes') ?>"><?= e(trans('backend::lang.form.cancel')) ?></a>
</span>
</div>
</div>
<?= Form::close() ?>
<?php else: ?>
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
<p><a href="<?= Backend::url('serenitynow/cacheroute/cacheroutes') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')) ?></a></p>
<?php endif ?>

View File

@@ -1 +0,0 @@
<?= $this->listRender() ?>

View File

@@ -1,22 +0,0 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('serenitynow/cacheroute/cacheroutes') ?>">CacheRoutes</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?php if (!$this->fatalError): ?>
<div class="form-preview">
<?= $this->formRenderPreview() ?>
</div>
<?php else: ?>
<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<?php endif ?>
<p>
<a href="<?= Backend::url('serenitynow/cacheroute/cacheroutes') ?>" class="btn btn-default oc-icon-chevron-left">
<?= e(trans('backend::lang.form.return_to_list')) ?>
</a>
</p>

View File

@@ -1,8 +0,0 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('serenitynow/cacheroute/cacheroutes') ?>">CacheRoutes</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?= $this->reorderRender() ?>

View File

@@ -1,54 +0,0 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('serenitynow/cacheroute/cacheroutes') ?>">CacheRoutes</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?php if (!$this->fatalError): ?>
<?= Form::open(['class' => 'layout']) ?>
<div class="layout-row">
<?= $this->formRender() ?>
</div>
<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-request-data="redirect:0"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-primary">
<?= e(trans('backend::lang.form.save')) ?>
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-default">
<?= e(trans('backend::lang.form.save_and_close')) ?>
</button>
<button
type="button"
class="oc-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-load-indicator="<?= e(trans('backend::lang.form.deleting')) ?>"
data-request-confirm="<?= e(trans('backend::lang.form.confirm_delete')) ?>">
</button>
<span class="btn-text">
<?= e(trans('backend::lang.form.or')) ?> <a href="<?= Backend::url('serenitynow/cacheroute/cacheroutes') ?>"><?= e(trans('backend::lang.form.cancel')) ?></a>
</span>
</div>
</div>
<?= Form::close() ?>
<?php else: ?>
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
<p><a href="<?= Backend::url('serenitynow/cacheroute/cacheroutes') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')) ?></a></p>
<?php endif ?>

View File

@@ -1,11 +0,0 @@
<?php return [
'plugin' => [
'name' => 'CacheRoute',
'description' => 'Speeds up your application by caching output associated with specified routes',
'route_pattern' => 'Route Pattern',
'cache_ttl' => 'TTL',
'cache_ttl_comment' => 'TTL In Minutes',
'manage_cache_route' => 'Manage CacheRoute',
'sort_order' => 'Sort Order',
],
];

View File

@@ -1,31 +0,0 @@
<?php namespace SerenityNow\Cacheroute\Models;
use Model;
/**
* Model
*/
class CacheRoute extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\Sortable;
/*
* Validation
*/
public $rules = [
'route_pattern' => 'required|unique:serenitynow_cacheroute_routes',
'cache_ttl' => 'integer',
];
/*
* Disable timestamps by default.
* Remove this line if timestamps are defined in the database table.
*/
public $timestamps = false;
/**
* @var string The database table used by the model.
*/
public $table = 'serenitynow_cacheroute_routes';
}

View File

@@ -1,14 +0,0 @@
columns:
route_pattern:
label: 'serenitynow.cacheroute::lang.plugin.route_pattern'
type: text
searchable: true
sortable: true
cache_ttl:
label: 'serenitynow.cacheroute::lang.plugin.cache_ttl'
type: number
sortable: true
sort_order:
label: 'serenitynow.cacheroute::lang.plugin.sort_order'
type: number
sortable: true

View File

@@ -1,14 +0,0 @@
fields:
route_pattern:
label: 'serenitynow.cacheroute::lang.plugin.route_pattern'
oc.commentPosition: ''
span: auto
required: 1
type: text
cache_ttl:
label: 'serenitynow.cacheroute::lang.plugin.cache_ttl'
span: auto
default: '10'
required: 1
type: text
comment: 'serenitynow.cacheroute::lang.plugin.cache_ttl_comment'

View File

@@ -1,17 +0,0 @@
plugin:
name: 'serenitynow.cacheroute::lang.plugin.name'
description: 'serenitynow.cacheroute::lang.plugin.description'
author: 'Shankar Manamalkav'
icon: oc-icon-fighter-jet
homepage: ''
permissions:
serenitynow.cacheroute.manage_cacheroute:
tab: 'serenitynow.cacheroute::lang.plugin.name'
label: 'serenitynow.cacheroute::lang.plugin.manage_cache_route'
navigation:
CacheRoute:
label: 'serenitynow.cacheroute::lang.plugin.name'
url: serenitynow/cacheroute/cacheroutes
icon: icon-fighter-jet
permissions:
- serenitynow.cacheroute.manage_cacheroute

View File

@@ -1,23 +0,0 @@
<?php namespace SerenityNow\Cacheroute\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableCreateSerenitynowCacherouteRoutes extends Migration
{
public function up()
{
Schema::create('serenitynow_cacheroute_routes', function($table)
{
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('route_pattern', 255);
$table->integer('cache_ttl');
});
}
public function down()
{
Schema::dropIfExists('serenitynow_cacheroute_routes');
}
}

View File

@@ -1,23 +0,0 @@
<?php namespace SerenityNow\Cacheroute\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateSerenitynowCacherouteRoutes extends Migration
{
public function up()
{
Schema::table('serenitynow_cacheroute_routes', function($table)
{
$table->integer('sort_order')->nullable()->unsigned();
});
}
public function down()
{
Schema::table('serenitynow_cacheroute_routes', function($table)
{
$table->dropColumn('sort_order');
});
}
}

View File

@@ -1,14 +0,0 @@
1.0.1:
- 'Initialize plugin.'
1.0.2:
- 'Created table serenitynow_cacheroute_routes'
- builder_table_create_serenitynow_cacheroute_routes.php
1.0.3:
- 'Updated table serenitynow_cacheroute_routes to have Sort_order - required for reorder'
- builder_table_update_serenitynow_cacheroute_routes.php
1.0.4:
- 'Remove sort_order field from create form'
- 'Set default sort order for list (sort_order asc)'
- 'add icon for reorder button'
1.0.5:
- 'Several updates to cache-debugging appearance and behavior by mrbohnke'