General
FluxBB versions
Appendix
Cache
fluxbb-cache is an API abstraction around various different cache stores available for PHP. Filters are supported to allow encoding of data during storage.
For cache stores that do not support data expiration (i.e. use of TTL) it is emulated.
Backend adapters
We currently support the following data stores as cache backend:
- flat-file storage
- Zend Cache Extension (both disk and shared memory supported)
Serializers
Serializers can be plugged into cache adapters to serialize cached data into one of the following formats:
- JSON (does not correctly serialize associative arrays or objects with protected/private attributes)
Filters
Filters can be plugged into cache adapters in the same way as serializers and can be used e.g. for compressing or encrypting the data. We currently support the following filters:
Compression
Encryption
API
Creation
\fluxbb\cache\Cache::load($type, $args = array(), $serializer_type = false, $serializer_args = array());
Storing
$cache→set($key, $data, $ttl = 0); $cache→get($key); $cache→delete($key); $cache→clear();
Filters & Serializers
Statistics
$cache→inserts; $cache→hits; $cache→misses;
Example usage
Code
// We want a file-based cache in the /tmp/php-cache/ dir - this will be created if possible. Obviously this path won't work on Windows! $cache = \fluxbb\cache\Cache::load('File', array('dir' => '/tmp/php-cache/')); // If we have the mcrypt extension let's encrypt the cache if (extension_loaded('mcrypt')) { echo 'Adding mcrypt filter.'."\n"; $cache->addFilter('MCrypt', array('secret' => 'i like ponies')); } // Check if there is already a value cached $value = $cache->get('test'); echo ($value === \fluxbb\cache\Cache::NOT_FOUND ? 'Value not found in cache.' : 'Value: '.$value)."\n"; // Store a new unique ID in the cache $uniqid = uniqid(); echo 'Storing: '.$uniqid."\n"; $cache->set('test', $uniqid); // Check that the new value was stored correctly $value = $cache->get('test'); echo ($value === \fluxbb\cache\Cache::NOT_FOUND ? 'Value not found in cache.' : 'Value: '.$value)."\n";
Output
Adding mcrypt filter. Value not found in cache. Storing: 4d35ca30ab630 Value: 4d35ca30ab630
