/PHP-APCCache

Abstract APC caching class for clean cache storage and retrieval.

Primary LanguagePHPMIT LicenseMIT

PHP-APCCache

The PHP-APCCache library includes just one statically accessed class which acts as a wrapper for PHP's native caching engine, APC. While not too popular when compared with it's neighbour Memcached (due most likely to not being distributed), APC is still a very solid, very fast local caching engine which can be useful in a one-server environment.

Customary functionality with the data-store include flush, read and write capabilities. Added functionality includes analytic methods to view the misses (aka unsuccessful reads), reads and writes with the data-store.

One quirk of this class is it's dependency on the JSON extension/module. In order to allow for the storage of the false boolean value, the JSON extension is used to encode certain data values. This is a requirement due to APC's structure, and it's lacking of flags to determine if a read was successfully evaluated, regardless of the return value.

Write/Read Example

<?php

    // dependency
    require_once APP . '/vendors/PHP-APCCache/APCCache.class.php';
    
    // write to cache; read; exit script
    APCCache::write('oliver', 'nassar');
    echo APCCache::read('oliver');
    exit(0);

The above example simply writes to the APC data-store, reads from it, and exits the script. Nothing fancy, and super-straightforward.