PHP Classes

Simple Cache System: Store and retrieve cached data in MySQL and files

Recommend this page to a friend!
  Info   View files Example   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 135 This week: 1All time: 9,273 This week: 560Up
Version License PHP version Categories
atto-cache 1.0.0GNU Free Document...5.5PHP 5, Databases, Files and Folders, C...
Description 

Author

This package can store and retrieve cached data in MySQL and files.

It provides a base class that performs several cache management operations like storing a cache value with a key and retrieve or invalidate a stored cached value.

The package also provide classes that perform the actual storage operations in different containers like a MySQL database table, files, or a dummy container that does not store anything just for testing purposes.

Picture of Andrei Alexandru
  Performance   Level  
Name: Andrei Alexandru <contact>
Classes: 4 packages by
Country: Spain Spain
Age: 38
All time rank: 251565 in Spain Spain
Week rank: 416 Up14 in Spain Spain Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Example

<?php

use Atto\Cache\Cache;

require
'Atto/Cache/Cache.php';
require
'Atto/Cache/Item.php';
require
'Atto/Cache/Storage.php';
require
'MySQLStorage.php';


// Lets create this storage now, a custom one
$storage = new MySQLStorage('localhost', 'root', '', 'database', 'cache');

// We use the MySQL Storage engine now
$cache = new Cache($storage, 60); // By default all items have 60 seconds of time to live

// Create some random data
$data = ['foo', 'bar', 'baz'];

// Store new items
$cache->store('some.id.key', $data); // $data will live for 60 seconds (default - Cache constructor)
$cache->store('another.key', $data, 60 * 60 * 24 * 7); // Now $data will live for 7 days
$cache->store('forever', $data, 0); // Using a $ttl less than 1 will indicate that this item never expires

// Retrieve items from the cache
$data = $cache->get('some.id.key');

print_r($cache->get('some.id.key'));
print_r($cache->get('forever'));

if (
$data === null) {
   
// $data does not exist in the cache storage
   
$data = ['foo', 'bar', 'baz'];
}

// Invalidate data
$cache->invalidate('another.key'); // This will remove an item from the cache storage


  Files folder image Files  
File Role Description
Files folder imageAtto (1 directory)
Accessible without login Plain text file CacheExtendedTest.php Example How to use the MySQLStorage we created.
Accessible without login Plain text file CacheTest.php Example Usage and testing
Accessible without login Plain text file MySQLStorage.php Example Example of an external storage

  Files folder image Files  /  Atto  
File Role Description
Files folder imageCache (3 files, 1 directory)

  Files folder image Files  /  Atto  /  Cache  
File Role Description
Files folder imageStorage (2 files)
  Accessible without login Plain text file Cache.php Class Main Cache class
  Accessible without login Plain text file Item.php Class Item for the cache system
  Accessible without login Plain text file Storage.php Class Storage interface

  Files folder image Files  /  Atto  /  Cache  /  Storage  
File Role Description
  Accessible without login Plain text file FileStorage.php Class File storage implementation.
  Accessible without login Plain text file NullStorage.php Class Null storage, if you dont want to use any cache for some reason

 Version Control Unique User Downloads Download Rankings  
 0%
Total:135
This week:1
All time:9,273
This week:560Up