Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eusonlito/cache

PHP Cache Interface
https://github.com/eusonlito/cache

Last synced: about 1 month ago
JSON representation

PHP Cache Interface

Awesome Lists containing this project

README

        

Cache
=====

This script works as simple interface with APC, Memcache, Memcached and Files to store data into cache.

You will can store different data into different cache methods (some examples into settings-example.php).

Examples
--------

#### Files cache

exists('js-files')) {
$content = $Cache->get('js-files');
} else {
$content = file_get_contents('https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
$content .= file_get_contents('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js');
$content .= file_get_contents('http://modernizr.com/i/js/modernizr.com-custom-1.6.js');

// Cache expired time is loaded from settings
// but you can set your own time in seconds from now
// Third parameter is optional
$Cache->set('js-files', $content, $custom_time);
}

#### Database Query cache (into APC)

exists($cache_key)) {
$rows = $Cache->get($cache_key);
} else {
$rows = mysql_fetch_assoc(mysql_query($query));

// Cache expired time is loaded from settings
// but you can set your own time in seconds from now
// Third parameter is optional
$Cache->set($cache_key, $rows, $custom_time);
}

#### Configuration cache (into Memcache)

exists($cache_key)) {
$configuration = $Cache->get($cache_key);
} else {
$configuration = array();

foreach ($config_files as $file) {
if (is_file(__DIR__.'/config/'.$file.'.php')) {
$configuration = array_replace_recursive($configuration, include(__DIR__.'/config/'.$file.'.php'));
}
}

// Cache expired time is loaded from settings
// but you can set your own time in seconds from now
// Third parameter is optional
$Cache->set($cache_key, $configuration, $custom_time);
}