2017 © Pedro Peláez
 

library cache

PHP Website Caching Library for HTML and Objects

image

philasearch/cache

PHP Website Caching Library for HTML and Objects

  • Friday, September 16, 2016
  • by tmuntan1
  • Repository
  • 1 Watchers
  • 1 Stars
  • 6,976 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 21 Versions
  • 3 % Grown

The README.md

Latest Stable Version Total Downloads Build Status, (*1)

PHP Cache

PHP Cache is a simple caching library for HTML and objects., (*2)

Installing

Add the following to your composer.json, (*3)

{
    "require": {
        "philasearch/cache": "1.1.*"
    }
}

Setup

Notice: I built this library agnostic to different cache providers, however, since I mainly use redis, redis is the only supported cache., (*4)

<?php

use Philasearch\Cache\Cache;
use Philasearch\Cache\CacheProviders;

// a redis cache at localhost and database of 0
$cache = new Cache ();

// a more specified cache
$cache = new Cache( CacheProviders::REDIS, 'tcp://127.0.0.1:6379?database=0');

Using Cached Objects

A cached object is a PHP object that has its values stored in the cache for easy storage and retrieval. In redis, this is done through the hash data type. When you recreate the object with the correct cache key, the object will be automatically resumed to its previous state., (*5)

<?php

use Philasearch\Cache\Cache;
use Philasearch\Cache\CacheProviders;

$cache = new Cache();

// a basic cached object
$object = $cache->createObject('cache_key'); 

// a cached object that expires in 10 seconds
$object = $cache->createObject('cache_key', 10);

// a cached object with a value foo that equals bar.
$object = $cache->createObject('cache_key', 0, ['foo' => 'bar']);

// filling the object with an array of variables
$object->fill(['foo' => 'bar']);

// setting a variable directly
$object->set('foo', 'bar');

// getting a variable
$foo = $object->get('foo');

Using Cached Trees

Cached trees are a way of having tree objects stored in the cache. These trees are also automatically resumed to the previous state if created with the same key., (*6)

<?php

use Philasearch\Cache\Cache;
use Philasearch\Cache\CacheProviders;

$cache = new Cache();

// a basic tree
$tree = $cache->createTree('cached_key');

// a tree that expires after 10 seconds
$tree = $cache->createTree('cached_key', 10);

// a root node with the id of 1 ('the id can also be a string')
$root = $tree->makeRootNode(1);

// a root node with the id of 1 and a value of foo that equals bar
$root = $tree->makeRootNode(1, ['foo' => 'bar']);

// set the value foo to bar
$root->set('foo', 'bar');

// get the value stored under bar
$root->get('foo');

// add a new child
$node = $root->addChild(2);

// add a new child with the value foo equaling bar
$node = $root->addChild(2, ['foo' => 'bar']);

// saving the tree
$tree->save();

// turns the tree to an array starting from root
$tree->getArray();

// turns the tree to an array starting at the child with the id of 2
$tree->getArray(2);

The Versions

16/09 2016

dev-master

9999999-dev https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

16/09 2016

1.1.11

1.1.11.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

01/09 2016

1.1.10

1.1.10.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

01/09 2016

1.1.9

1.1.9.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

01/09 2016

1.1.8

1.1.8.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

05/04 2016

1.1.7

1.1.7.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

12/11 2015

1.1.6

1.1.6.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

22/10 2015

1.1.5

1.1.5.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

06/10 2015

1.1.4

1.1.4.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

06/10 2015

1.1.3

1.1.3.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

06/10 2015

1.1.2

1.1.2.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

01/10 2015

1.1.1

1.1.1.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

01/10 2015

1.1.0

1.1.0.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

07/08 2015

1.0.7

1.0.7.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

13/07 2015

1.0.6

1.0.6.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

26/01 2015

1.0.5

1.0.5.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

19/12 2014

1.0.4

1.0.4.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

17/12 2014

1.0.3

1.0.3.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

11/12 2014

1.0.2

1.0.2.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

02/12 2014

1.0.1

1.0.1.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner

09/09 2014

1.0.0

1.0.0.0 https://github.com/philasearch/php-cache

PHP Website Caching Library for HTML and Objects

  Sources   Download

The Requires

 

The Development Requires

by Thomas Muntaner