I'm currently working on an Abstraction class/classes to essentially make an API for Memcache. Wincache, APC and Static File Cache.
The issue I'm trying to work around is that whilst Memcache, Wincache, APC are all designed caching methods. Caching to flat file using fopen, fwrite etc... works in a different way.
//Memcache
$c = new cache(cache::CACHE_MEMCACHE, 'localhost', 11211);
if (!$news = $c->get('news'))
{
$news = $db->news->get(1);
$c->set('news', $news, 300);
}
echo $news;
//APC
$c = new cache(cache::CACHE_APC);
if (!$news = $c->get('news'))
{
$news = $db->news->get(1);
$c->set('news', $news, 300);
}
echo $news;
//Wincache
$c = new cache(cache::CACHE_WINCACHE);
if (!$news = $c->get('news'))
{
$news = $db->news->get(1);
$c->set('news', $news, 300);
}
echo $news;
//Filecache (notice the duration has moved from set() to get()
$c = new cache(cache::CACHE_FILECACHE, '../cache/');
if (!$news = $c->get('news', 300))
{
$news = $db->news->get(1);
$c->set('news', $news);
}
As you can see from the quick dirty examples someone using the class would need to change all get/set calls throughout an application if they wanted to move from static file cache to memcache (if the disk IO started to jump)
The options I have been toying with are:
1: Use of an index. Possibly an XML (DOM or SimpleXML overhead dependent) file within the cache directory but this could get very big very quickly and would slow down the cache potentially removing the benefit of caching
2: Store the data data in the file with an expiry time string and initially call a fread method with a set length (length of the time string) if the expiry time hasn't expired call a 2nd read to get the rest of the cached object.
I want the module to be as portable as possible without the need for finding and installing various external classes/systems (obviously memcache, wincache and apc aren't always compiled with PHP)