288

Product support

Get help in the plugin support forum.

Categories

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 "about" cached (Add a new row with 'about' as the route_pattern and 10 as the TTL). 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 (using whatever driver 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.

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.

Icons made by Dave Gandy from www.flaticon.com is licensed by CC 3.0 BY

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/route patterns
  • The plugin uses Request::is('pattern') to check for a match

Note

  • Be mindful of what you are caching! This approach works best for relatively static global content.
  • You can verify functionality by entering "?debug" in the address bar. For a cached route, You should see the text "CACHED" preceding the page content.
  • The cache key is a slug of the request url (without any 'get' params) i.e. str_slug($request->url())
  • use php artisan cache:clear to clear your cache (remember to do this when adding new route patterns!)

  • Found the plugin useful on 30 Jul, 2018

    Any idea to cache the index page ? Route pattern can't be empty...

  • Found the plugin useful on 2 Aug, 2017

    Now websites are loading much faster!

  • Found the plugin useful on 19 Dec, 2016

    It works perfectly! Thank you very much :)

1.0.5

Several updates to cache-debugging appearance and behavior by mrbohnke

Nov 16, 2016

1.0.4

Remove sort_order field from create form

Aug 30, 2016

1.0.3

Updated table serenitynow_cacheroute_routes to have Sort_order - required for reorder

Aug 25, 2016

1.0.2

Created table serenitynow_cacheroute_routes

Aug 25, 2016

1.0.1

Initialize plugin.

Aug 25, 2016