PHP Classes

How to Use a PHP Cache Library That Can Adapt to Each Storage Container Type Using the Package Unicache: Store cached data in different storage types

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-09-30 (5 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
unicache 1.3.0Artistic License5PHP 5, Cache
Description 

Author

This package can store cached data in different storage types.

It provides a cache engine that can store data in different storage containers using driver classes that implement functions to store and retrieve cached data adapted to the type of storage container.

Currently, the package provides adapter classes to store cached data using:

- APC

- Apcu

- File

- Memcached

- Memory

- Redis

- Cache

The package implements the same cache engine in PHP, JavaScript, or Python.

Picture of Nikos M.
Name: Nikos M. is available for providing paid consulting. Contact Nikos M. .
Classes: 21 packages by
Country: Greece Greece
Age: 49
All time rank: 8449 in Greece Greece
Week rank: 195 Up2 in Greece Greece Up
Innovation award
Innovation award
Nominee: 8x

Winner: 2x

Instructions

Please read this document, to learn how to store and retrieve data from different types of storage containers.

Example

<?php
require_once(dirname(dirname(__FILE__)) . '/src/php/Unicache.php');

echo
'UNICACHE::VERSION = ' . UNICACHE_Factory::VERSION . PHP_EOL;

$config = array(
   
'cacheType' => 'FILE',
   
'prefix' => 'foo_',
   
   
'FILE' => array(
       
'cacheDir' => dirname(__FILE__).'/cache1' // will be created if it does not exist
   
)
);


$cache = UNICACHE_Factory::getCache($config);

$cache->put('key', 'val', 10);

sleep(2);

$val = $cache->get('key');

print_r(array('val', $val));

sleep(12);

$val = $cache->get('key');

print_r(array('val', $val));


Details

UNICACHE

An agnostic caching framework for PHP, JavaScript, Python

Unicache

 ____ ___      .__                     .__
|    |   \____ |__| ____ _____    ____ |  |__   ____
|    |   /    \|  |/ ___\\__  \ _/ ___\|  |  \_/ __ \
|    |  /   |  \  \  \___ / __ \\  \___|   Y  \  ___/
|______/|___|  /__|\___  >____  /\___  >___|  /\___  >
             \/        \/     \/     \/     \/     \/

Logo Ascii Art by Text-to-Ascii Art Generator

version: 1.3.0

Contents

How to Use

PHP

This is a caching framework for applications that is agnostic.

This means that one can use it easily in her web applications that use any given framework or not use any framework at all.

The framework is configured by a config file which easily gets together all parameters, like type of caching, time to live, post-cache user defined filtering and per-page user defined cache disable.

A demo is included with the package. One simply adds an include directive and bang you have the most advanced caching.

NodeJS

Supports both node-style callback-based methods (nodebacks) plus promise-based methods (if Promises are supported). Each method (i.e get, put, remove, clear, gc) has an associated method that returns a promise (i.e getPromise, putPromise, removePromise, clearPromise, gcPromise). Also some cache types (i.e memory-based and file-based) support synchronous operations as well (if no callback is provided synchronous processing takes place).

Browser

Supports both callback-based methods plus promise-based methods (if Promises are supported). Each method (i.e get, put, remove, clear, gc) has an associated method that returns a promise (i.e getPromise, putPromise, removePromise, clearPromise, gcPromise). Also some cache types (i.e memory-based, cookie-based, webStorage-based) support synchronous operations as well (if no callback is provided synchronous processing takes place).

Types of Caching Supported

server-side

  • `In-Memory` caching (default) PHP + NodeJS
  • `File`-based caching PHP + NodeJS
  • `APC` PHP
  • `APCU` PHP (requires `apcu` extension)
  • `XCache` PHP (requires `xcache` extension)
  • `Memcached` PHP (requires `Memcache` or `Memcached` extension) + NodeJS (requires node-memcached module)
  • `Redis` PHP + NodeJS (requires node-redis module)
  • it is easy to extend to other methods as well.

client-side

  • `In-Memory` caching (default)
  • `Cookie`-based caching
  • `LocalStorage`
  • `SessionStorage`
  • `IndexedDb`-based caching
  • `WebSql`-based caching (supported only on some browers, eg Chrome)
  • it is easy to extend to other methods as well.

TODO

  • add `python` implementations
  • add client-side/browser support for `webSql` caching [DONE]
  • add support for Redis [DONE]
  • add support for xCache [DONE]
  • `nodejs` and `browser` cache manipulation methods use standard callbacks (i.e as last argument w/ signature: `function(err, result)`) [DONE] and also promises (via same method names with "`Promise`" suffix) [DONE]

ChangeLog

see also:

  • ModelView a simple, fast, powerful and flexible MVVM framework for JavaScript
  • tico a tiny, super-simple MVC framework for PHP
  • LoginManager a simple, barebones agnostic login manager for PHP, JavaScript, Python
  • SimpleCaptcha a simple, image-based, mathematical captcha with increasing levels of difficulty for PHP, JavaScript, Python
  • Dromeo a flexible, and powerful agnostic router for PHP, JavaScript, Python
  • PublishSubscribe a simple and flexible publish-subscribe pattern implementation for PHP, JavaScript, Python
  • Localizer a simple and versatile localization class (l10n) for PHP, JavaScript, Python
  • Importer simple class &amp; dependency manager and loader for PHP, JavaScript, Python
  • EazyHttp, easy, simple and fast HTTP requests for PHP, JavaScript, Python
  • Contemplate a fast and versatile isomorphic template engine for PHP, JavaScript, Python
  • HtmlWidget html widgets, made as simple as possible, both client and server, both desktop and mobile, can be used as (template) plugins and/or standalone for PHP, JavaScript, Python (can be used as plugins for Contemplate)
  • Paginator simple and flexible pagination controls generator for PHP, JavaScript, Python
  • Formal a simple and versatile (Form) Data validation framework based on Rules for PHP, JavaScript, Python
  • Dialect a cross-vendor &amp; cross-platform SQL Query Builder, based on GrammarTemplate, for PHP, JavaScript, Python
  • DialectORM an Object-Relational-Mapper (ORM) and Object-Document-Mapper (ODM), based on Dialect, for PHP, JavaScript, Python
  • Unicache a simple and flexible agnostic caching framework, supporting various platforms, for PHP, JavaScript, Python
  • Xpresion a simple and flexible eXpression parser engine (with custom functions and variables support), based on GrammarTemplate, for PHP, JavaScript, Python
  • Regex Analyzer/Composer Regular Expression Analyzer and Composer for PHP, JavaScript, Python

Screenshots (1)  
  • unicache.jpg
  Files folder image Files (31)  
File Role Description
Files folder imageexamples (1 file)
Files folder imagesrc (3 directories)
Files folder imagetest (3 files)
Accessible without login Plain text file readme.md Doc. Documentation

  Files folder image Files (31)  /  examples  
File Role Description
  Accessible without login Plain text file cachedemo.php Example Example script

  Files folder image Files (31)  /  src  
File Role Description
Files folder imagejs (2 directories)
Files folder imagephp (3 files, 1 directory)
Files folder imagepy (1 file)

  Files folder image Files (31)  /  src  /  js  
File Role Description
Files folder imagebrowser (2 files, 1 directory)
Files folder imagenode (1 file, 1 directory)

  Files folder image Files (31)  /  src  /  js  /  browser  
File Role Description
Files folder imageadapters (6 files)
  Accessible without login Plain text file Unicache.js Data Auxiliary data
  Accessible without login Plain text file Unicache.min.js Data Auxiliary data

  Files folder image Files (31)  /  src  /  js  /  browser  /  adapters  
File Role Description
  Accessible without login Plain text file UnicacheCookie.js Data Auxiliary data
  Accessible without login Plain text file UnicacheIndexedDb.js Data Auxiliary data
  Accessible without login Plain text file UnicacheLocalStorage.js Data Auxiliary data
  Accessible without login Plain text file UnicacheMemory.js Data Auxiliary data
  Accessible without login Plain text file UnicacheSessionStorage.js Data Auxiliary data
  Accessible without login Plain text file UnicacheWebSql.js Data Auxiliary data

  Files folder image Files (31)  /  src  /  js  /  node  
File Role Description
Files folder imageadapters (4 files)
  Accessible without login Plain text file Unicache.js Data Auxiliary data

  Files folder image Files (31)  /  src  /  js  /  node  /  adapters  
File Role Description
  Accessible without login Plain text file UnicacheFile.js Data Auxiliary data
  Accessible without login Plain text file UnicacheMemcached.js Data Auxiliary data
  Accessible without login Plain text file UnicacheMemory.js Data Auxiliary data
  Accessible without login Plain text file UnicacheRedis.js Data Auxiliary data

  Files folder image Files (31)  /  src  /  php  
File Role Description
Files folder imageadapters (7 files, 1 directory)
  Accessible without login Plain text file cache-this.php Aux. Auxiliary script
  Accessible without login Plain text file unicache-config.php Conf. Configuration script
  Plain text file Unicache.php Class Class source

  Files folder image Files (31)  /  src  /  php  /  adapters  
File Role Description
Files folder imagedrivers (1 file)
  Plain text file UnicacheApc.php Class Class source
  Plain text file UnicacheApcu.php Class Class source
  Plain text file UnicacheFile.php Class Class source
  Plain text file UnicacheMemcached.php Class Class source
  Plain text file UnicacheMemory.php Class Class source
  Plain text file UnicacheRedis.php Class Class source
  Plain text file UnicacheXCache.php Class Class source

  Files folder image Files (31)  /  src  /  php  /  adapters  /  drivers  
File Role Description
  Plain text file redis.php Class Class source

  Files folder image Files (31)  /  src  /  py  
File Role Description
  Accessible without login Plain text file todo.txt Doc. Documentation

  Files folder image Files (31)  /  test  
File Role Description
  Accessible without login HTML file test.html Doc. Documentation
  Accessible without login Plain text file test.js Data Auxiliary data
  Accessible without login Plain text file test.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0