2017 © Pedro Peláez
 

library juggernaut

A caching module for PHP that includes adapters for File System, APC and Memcached. It also includes a number of helper classes for DB caching and full page cache

image

zoopcommerce/juggernaut

A caching module for PHP that includes adapters for File System, APC and Memcached. It also includes a number of helper classes for DB caching and full page cache

  • Saturday, April 26, 2014
  • by zoopcommerce
  • Repository
  • 2 Watchers
  • 6 Stars
  • 1,433 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 3 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Juggernaut

Introduction

Juggernaut is a super fast PHP cache. It has a number of storage adapters and a few simple helpers to get you up and caching quickly., (*1)

One of the best aspects of this module is that it provides flood protection both on the initial cache creation - by queuing subsequent requests - but also on re-caching - by serving old cache for subsequent requests until the new cache has been re-created., (*2)

These two features allow Juggernaut to be at least 100% faster than the Zend Framework 2 cache adapters in normal use, and up to 270% faster on highly concurrent applications., (*3)

Installation

Install the module using Composer into your application's vendor directory. Add the following line to your composer.json., (*4)

{
    "require": {
        "zoopcommerce/juggernaut": "dev-master"
    }
}

Usage

You can use Juggernaut by directly instantiating a storage adapter and calling set/get., (*5)

Key-Value-Pair Caching Using Storage Adapters

File System

// you should always store the cache below the web root for security!!
$cacheDirectory = __DIR__ . '../cache';

$cache = new Zoop\Juggernaut\Adapter\FileSystem($cacheDirectory);

$key = 'yourUniqueKey';

$data = $cache->getItem($key, $success);

// check if cache hit/miss
if ($success === false) {
  // cache missed so now we have to execute
    // some query that takes a long time
    for($i=0;$i<1000000;$i++) {
        $data = rand(0, 10000);
    }

    //save it to cache
    $cache->setItem($key, $data);
    echo $data;
} else {
    // cache hit!
    echo $data;
}

MongoDB


$mongo = new MongoClient('mongodb://username:password@localhost:27017'); $collection = $mongo->selectCollection('Cache'); $cache = new Zoop\Juggernaut\Adapter\MongoDB($collection); $key = 'yourUniqueKey'; $data = $cache->getItem($key, $success); // check if cache hit/miss if ($success === false) { // cache missed so now we have to execute // some query that takes a long time for($i=0;$i<1000000;$i++) { $data = rand(0, 10000); } //save it to cache $cache->setItem($key, $data); echo $data; } else { // cache hit! echo $data; }

Memcached

//coming soon

MySQL

//coming soon

Helpers

There are a few helpers that will expidite the usage of Juggernaut., (*6)

Full Page

As the name suggests, the "Full Page" helper will store the rendered page directly to cache. This results in blindingly fast page loads., (*7)

To use this script just place the following at the top of your pages., (*8)

$pageTtl = 600; //10 mins
$cacheDirectory = __DIR__ . '../cache';

$adapter = new Zoop\Juggernaut\Adapter\FileSystem($cacheDirectory);

$pageCache = new Zoop\Juggernaut\Helper\FullPage($adapter, $pageTtl);
$pageCache->start();

You can use any of the provided adapters to store the full page cache. eg., (*9)

$pageTtl = 600; //10 mins
$database='MyMongoDb';
$username='mymongouser';
$password='mymongopass';

$adapter = new Zoop\Juggernaut\Adapter\MongoDB($database, $username, $password);

$pageCache = new Zoop\Juggernaut\Helper\FullPage($adapter, $pageTtl);
$pageCache->start();

There's no need to manually save the rendered page to cache as the script will automatically flush the page output to the cache adapter once the script exits., (*10)

Database

MySQLi

You can use the mysqli helper to automatically cache your sql queries., (*11)

$cacheDirectory = __DIR__ . '../cache';
$adapter = new Zoop\Juggernaut\Adapter\FileSystem($cacheDirectory);

$db = new Zoop\Juggernaut\Helper\Database\Mysqli($cache);
$db->connect($host, $username, $passwd, $database);

$q="SELECT COUNT(`pageviews`) as 'pageviews' FROM `analytics` GROUP BY `date`";
$r = $db->query($q, 600); //second arg is ttl
if($r!==false) {
    $pageviews = $db->fetchRow($q)['pageviews'];
}

As you can see you don't have to worry if the cache exists or not as the helper does all the heavy lifting., (*12)

Coming soon

  • Unit tests
  • Working examples
  • MySQL adapter
  • Memcached adapter
  • MongoDB helper

The Versions

26/04 2014

dev-master

9999999-dev http://github.com/zoopcommerce/juggernaut

A caching module for PHP that includes adapters for File System, APC and Memcached. It also includes a number of helper classes for DB caching and full page cache

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php caching

26/04 2014

1.2.0

1.2.0.0 http://github.com/zoopcommerce/juggernaut

A caching module for PHP that includes adapters for File System, APC and Memcached. It also includes a number of helper classes for DB caching and full page cache

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php caching

22/04 2014

1.1.3

1.1.3.0 http://github.com/zoopcommerce/juggernaut

A caching module for PHP that includes adapters for File System, APC and Memcached. It also includes a number of helper classes for DB caching and full page cache

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php caching

25/01 2014

1.1.2

1.1.2.0 http://github.com/zoopcommerce/juggernaut

A caching module for PHP that includes adapters for File System, APC and Memcached. It also includes a number of helper classes for DB caching and full page cache

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php caching

11/09 2013

1.1.1

1.1.1.0 http://github.com/zoopcommerce/juggernaut

A caching module for PHP that includes adapters for File System, APC and Memcached. It also includes a number of helper classes for DB caching and full page cache

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php caching

05/09 2013

1.1

1.1.0.0 http://github.com/zoopcommerce/juggernaut

A caching module for PHP that includes adapters for File System, APC and Memcached. It also includes a number of helper classes for DB caching and full page cache

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php caching

10/07 2013

1.0

1.0.0.0 http://github.com/zoopcommerce/juggernaut

A caching module for PHP that includes adapters for File System, APC and Memcached. It also includes a number of helper classes for DB caching and full page cache

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php caching