Giter Club home page Giter Club logo

oc-cacheroute-plugin's Introduction

##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())

oc-cacheroute-plugin's People

Contributors

mnshankar avatar cceglia avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.