项目作者: Biz-mark

项目描述 :
OctoberCMS Lightning fast static files cache system
高级语言: PHP
项目地址: git://github.com/Biz-mark/Quicksilver.git
创建时间: 2019-07-01T20:58:25Z
项目社区:https://github.com/Biz-mark/Quicksilver

开源协议:MIT License

下载


OctoberCMS lightning fast static files cache system

Quicksilver in OctoberCMS Marketplace

Lightning fast cache system that converts your website page to static .html, .xml, .json and other files.

Store your pages as static files and deliver it to your visitors in milliseconds!

Features

  • No additional configuration needed! Easy to use on shared hosting! Install in one click.
  • Smart content type determination by headers or file extension, with ability to be extended.
  • Full Storage service support. You can configure custom cache disk via config.
  • Optional query strings support configurable from backend.
  • Optional excluded paths configurable from backend.
  • Easy extendability by October CMS events.
  • No dependencies, works with October CMS v1.1, v2, v3.
  • Can be used with October CMS AJAX Framework!

Notice

This plugin stores the response of your pages as static files. You should be aware that cached pages are the same to everyone no matter in what state (logged or not) visitor session are. Otherwise, personal information can be seen by every visitor.

Use Quicksilver settings to set excluded paths, so pages with sensitive information will not be cached.


Requirements

  • PHP 7.4 and above
  • October CMS v1.1 or v2 or v3

Installation

  1. php artisan plugin:install BizMark.Quicksilver

Additional configuration

Quicksilver can be configured additionally so webserver can check for cached pages by itself,
completely ignoring application booting.

Apache

  1. Open .htaccess and add the following before Standard routes section

    1. ##
    2. ## Serve Cached Page If Available
    3. ##
    4. RewriteCond %{REQUEST_URI} ^/?$
    5. RewriteCond %{DOCUMENT_ROOT}/storage/quicksilver/cache/qs_index_qs.html -f
    6. RewriteRule .? /storage/quicksilver/cache/qs_index_qs.html [L]
    7. RewriteCond %{DOCUMENT_ROOT}/storage/quicksilver/cache%{REQUEST_URI}.html -f
    8. RewriteRule . /storage/quicksilver/cache%{REQUEST_URI}.html [L]
    9. RewriteCond %{HTTP:X-Requested-With} XMLHttpRequest
    10. RewriteRule !^index.php index.php [L,NC]
  2. Comment out following line in White listed folders section.

    1. RewriteRule !^index.php index.php [L,NC]
  3. Be sure that plugin can create/write/read “storage/quicksilver/cache” folder in your storage path.

Nginx

  1. location = / {
  2. try_files /storage/quicksilver/cache/qs_index_qs.html /index.php?$query_string;
  3. }
  4. location / {
  5. try_files $uri $uri/ /storage/quicksilver/cache/$uri.html /storage/quicksilver/cache/$uri.json /index.php?$query_string;
  6. }

If you need to send ajax requests to cached url, you should use this construction

  1. location / {
  2. if ($request_method = POST ) {
  3. rewrite ^/.*$ /index.php last;
  4. }
  5. try_files $uri $uri/ /storage/quicksilver/cache/$uri.html /storage/quicksilver/cache/$uri.json /index.php?$query_string;
  6. }

Ignoring the cached files

Don’t forget to put Quicksilver folder in your .gitignore.

  1. /storage/quicksilver

Clearing the cache

  1. php artisan quicksilver:clear

Or to clear specific route

  1. php artisan quicksilver:clear {path}

Events

These events called when request and response are validated if returned true, Quicksilver will continue validation.

  • bizmark.quicksilver.is_request_valid - bool
  1. Event::listen('bizmark.quicksilver.is_request_valid', function(\Illuminate\Http\Request $request) {
  2. // request is valid, cache.
  3. return true;
  4. // request is invalid, don't cache.
  5. return false;
  6. });
  • bizmark.quicksilver.is_response_valid - bool
  1. Event::listen('bizmark.quicksilver.is_response_valid', function(\Symfony\Component\HttpFoundation\Response; $response) {
  2. // response is valid, cache.
  3. return true;
  4. // response is invalid, don't cache.
  5. return false;
  6. });

These events called before and after storing cached page, so you can modify contents of it.

  • bizmark.quicksilver.before_store - void

    1. Event::listen('bizmark.quicksilver.before_store', function(array $fileInformation) {
    2. // Contents of fileInformation
    3. // $fileInformation = [
    4. // name
    5. // extension
    6. // directory
    7. // mimeType
    8. // path
    9. // ];
    10. // ...
    11. });
  • bizmark.quicksilver.after_store - void

    1. Event::listen('bizmark.quicksilver.after_store', function(array $fileInformation) {
    2. // Contents of fileInformation
    3. // $fileInformation = [
    4. // name
    5. // extension
    6. // directory
    7. // mimeType
    8. // path
    9. // ];
    10. // ...
    11. });

© 2022, Nick Khaetsky at Biz-Mark under the GNU General Public License v2.0.