All-in-One Wrapper for APC, EAccelerator, xCache and Disk Cache

This library lists apc_* family of functions for eAccelerator, xCache or Disk Cache operations if APC or APCu is not available on server. When APC is installed and enabled, this library does nothing (because the desired functions are already available) – resulting in zero wrapper call overhead since all calls go directly to internal APC api.

In simple words, whether or not your PHP installation has a caching engine, you can always use apc_store, apc_fetch and apc_delete for your cache management.

This wrapper was written to abstract out or automate the cache engine selection. This wraps three basic read/write/delete functions of common caching engines and disk caching as well. I named all the functions after APC api so that whatever caching engine I have on my server, my application does not require a change, and in case my server has APC installed and enabled, I get the additional benefit of Zero overhead on internal function calls.

The Code

Installation & Configuration

Save the code as apc.php and include in your script. You have to define a valid cache path for Disk Caching.

Additionally, you would have to set appropriate permissions for your cache directory $apc_cache_dir to make it writable.

Storing, Fetching & Deleting Key-Value Pairs