Festi Cache
Festi Cache is a flexible caching library for the Festi Framework, providing multiple cache adapters including Memcache, Memcached, ArrayCache, and Pear Cache Lite. It allows efficient caching of data to improve application performance.
Installation
To install Festi Cache via Composer, add the following to your composer.json
:
{
"require": {
"festi-team/festi-framework-cache": "dev-master"
}
}
Usage
Initializing Cache
To use Festi Cache, initialize an adapter:
$cache = new Cacher(new MemcachedAdapter());
Storing and Retrieving Data
$key = 'user_123';
$value = ['name' => 'John Doe', 'email' => '[email protected]'];
$cache->set($key, $value, 3600); // Store for 1 hour
$data = $cache->get($key);
var_dump($data);
Deleting Cached Data
$cache->delete($key);
Available Cache Adapters
Festi Cache supports multiple caching backends:
- MemcacheAdapter – Uses PHP’s
memcache
extension. - MemcachedAdapter – Uses
memcached
extension for improved performance. - ArrayCacheAdapter – In-memory caching for temporary storage.
- PearCacheLiteAdapter – Uses PEAR’s
Cache_Lite
for lightweight file-based caching.
Exception Handling
Festi Cache provides built-in exception handling:
try {
$cache->set($key, $value, -1); // Invalid expiration time
} catch (CacheException $e) {
echo "Cache error: " . $e->getMessage();
}