Last Updated: February 25, 2016
·
1.334K
· gjerokrsteski

Create PHP DBA cache using Oracle Berkeley DB 4 with persistent connection

$cache = new Cache(
  '/your/path/to/the/cahe-file/cache.db4', 'db4'
);

$yorObject            = new ObjectYouWantToPutInCache();
$yourObjectIdentifier = 'your:cool:object:identifier';

// check if your object is in the cache.
// you also can ignore it, and let the CacheDba do it for you.
if (false == $cache->has($yourObjectIdentifier)) {
  $cache->delete($yourObjectIdentifier);
}

$cache->put($yourObjectIdentifier, $yorObject);

// than somewhere at your project.
$cache->get($yourObjectIdentifier);

// for the garbage collection 
// you can create an cron-job starting once a day.
$sweeper = new Sweeper($cache);
$sweeper->cleanAll();

// or clean all objects older than given expiration since now.
$sweeper->cleanOld();

Read more http://gjerokrsteski.github.com/php-dba-cache/