Coder Social home page Coder Social logo

html_cache's Introduction

/*
 * HtmlCache Plugin
 * Copyright (c) 2009 Matt Curry
 * http://pseudocoder.com
 * http://github.com/mcurry/html_cache
 *
 * @author      mattc <[email protected]>
 * @license     MIT
 *
 */
 
/* About */
Cake's core cache helper is great, but the files it outputs are PHP files, so it will never be as fast as
straight HTML files. This HTML Cache Helper writes out pure HTML, meaning the web server doesn't have to
touch PHP when a request is made.  Included is also a Croogo CMS (http://croogo.org) using the hooks system.

This plugin is for sites with high traffic pages that have nothing unique about the user on the page. I
use this helper on http://www.rsstalker.com. It handles the custom RSS feeds (currently around 13k), which
is perfect since there is nothing user specific in the XML. Each feed gets hit multiple times a day, by
multiple aggregators. This really adds up to a ton of requests.
 
/* Notes */
  * Nothing specific to a user on the page. No "Welcome, Matt" or shopping carts.
  * Cache will never expire (for non-Croogo version). See below for workaround.

/* Instructions */
  * Include the helper in your controller:
    var $helpers = array('HtmlCache.HtmlCache');
  * Or in a single action
    $this->helpers[] = 'HtmlCache.HtmlCache';
  * Update your webroot .htaccess file to include the following lines before CakePHP's Rewrite Cond
    (see extras/webroot.htaccess for an example):
    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{DOCUMENT_ROOT}/cache/$1/index.html -f
    RewriteRule ^(.*)$ /cache/$1/index.html [L]

/* Croogo Instructions */
  * Update your webroot .htaccess file to include the following lines before CakePHP's Rewrite Cond
    (see extras/webroot.htaccess for an example):
    RewriteCond %{DOCUMENT_ROOT}/cache/$1/index.html -f
    RewriteRule ^(.*)$ /cache/$1/index.html [L]
  * In the Croogo admin go to Extensions -> Hooks and active both the component and helper.
  * The Croogo version will automatically delete the cached file if there is a change to the content or a comment is added.
    
/* Tips */
  * To expire the cache I use a cron job which deletes old files from the directory.
  find /full/path/to/app/webroot/cache -mmin +360 | xargs rm -f
  * A sample htaccess file, cache.htaccess is included that will additionally gzip the cached files
  for even better performance.

html_cache's People

Contributors

mcurry avatar

Stargazers

 avatar

Watchers

 avatar  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.