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();
Written by Gjero Krsteski
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#