Using Memcached
Fri, 07/22/2011 - 21:49
Thread spawned from http://qcu.be/content/proposal-future-qcubed-qcubed-community#comment-6348
This really doesn't seem like it would be real difficult. I threw this together looking at the existing QCache class and the codegen template qcubed_query_methods.tpl. Purely a concept, not even sure if the code would work, but it could be a starting point for someone.
QMemcache
<?php
class QMemcache extends Memcache{
const MEMCACHE_SERVER = '127.0.0.1';
const MEMCACHE_PORT = 11211;
const MEMCACHE_EXPIRY = 100;
public function __construct(){
$this->connect(QMemcache::MEMCACHE_SERVER, QMemcache::MEMCACHE_PORT) or
die ("Unable to connect to Memcache server");
}
}
?>Codegen addition to qcubed_query_methods.tpl
<?php
public static function QueryArrayMemcached(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null, $blnForceUpdate = false) {
// Get the Database Object for this Class
$objDatabase = <%= $objTable->ClassName %>::GetDatabase();
$strQuery = <%= $objTable->ClassName %>::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
$strKey = 'qquery/<%= strtolower($objTable->ClassName) %>';
$objCache = new QMemcache();
$cacheData = $objCache->get($strKey);
if (!$cacheData || $blnForceUpdate) {
$objDbResult = $objQueryBuilder->Database->Query($strQuery);
$arrResult = <%= $objTable->ClassName %>::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes, $objQueryBuilder->ColumnAliasArray);
$objCache->set($strKey, serialize($arrResult), false, QMemcache::MEMCACHE_EXPIRY);
} else {
$arrResult = unserialize($cacheData);
}
return $arrResult;
}
?>
I am downloading slackware 13.37 (X86_64) and will download mongo and memcache then.... will try out how whether this works... :)