dev-master
9999999-dev http://github.com/inouet/file-cacheA simple PHP class for caching data in the filesystem.
MIT
The Requires
- php >=5.4.0
The Development Requires
by Taiji Inoue
file cache
Wallogit.com
2017 © Pedro Pelรกez
A simple PHP class for caching data in the filesystem.
A simple PHP class for caching, (*1)
<?php
require 'vendor/autoload.php';
$cache = new FileCache();
$id = "user/10";
$data = array(
'name' => 'John',
'age' => 20,
'sex' => 'f',
);
$lifetime = 3600; // cache lifetime (default: 3600)
$cache->save($id, $data, $lifetime);
$user = $cache->get($id);
// return false if cache is expired or does not exist
print_r($user);
output:, (*2)
Array
(
[name] => John
[age] => 20
[sex] => f
)
Cache files are stored in /tmp/cache directory by default. It will be saved under the folder hierarchy of 2., (*3)
$ tree /tmp/cache
/tmp/cache
โโโ a2
โโโ 24
โโโ a224b17e63b8eb3103a8c4679b7de2072b598c99.cache
Delete cache, (*4)
$cache->delete($id);
set parameter "cache_dir" to constructor, (*5)
<?php
$options = array('cache_dir' => __DIR__.'/cache');
$cache = new FileCache($options);
$cache->save("key", "value");
$ tree ./cache
./cache
โโโ 31
โโโ f3
โโโ 31f30ddbcb1bf8446576f0e64aa4c88a9f055e3c.cache
2 directories, 1 file
A simple PHP class for caching data in the filesystem.
MIT
file cache