summaryrefslogtreecommitdiff
path: root/classes/Memcached_DataObject.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-07-05 11:31:39 -0400
committerEvan Prodromou <evan@controlyourself.ca>2009-07-05 11:31:39 -0400
commit9f6bea473e22392c575d6957f9efc62a6faf7096 (patch)
treed777c476158e17c444b2bf997529e34b4eada971 /classes/Memcached_DataObject.php
parenteedfaa7d1a8e0f97175dfb832091250ca2e1f851 (diff)
cache failure to find in memcached
Diffstat (limited to 'classes/Memcached_DataObject.php')
-rw-r--r--classes/Memcached_DataObject.php50
1 files changed, 40 insertions, 10 deletions
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index f7cbb9d5b..96f8d520b 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -33,21 +33,41 @@ class Memcached_DataObject extends DB_DataObject
$k = $keys[0];
unset($i);
}
- $i = Memcached_DataObject::getcached($cls, $k, $v);
+ $i = self::getcached($cls, $k, $v);
if ($i) {
return $i;
} else {
$i = DB_DataObject::staticGet($cls, $k, $v);
if ($i) {
$i->encache();
+ } else {
+ self::cachenull($cls, $k, $v);
}
return $i;
}
}
+ function cachenull($cls, $k, $v)
+ {
+ $c = self::memcache();
+ if (empty($c)) {
+ return;
+ }
+ $c->set(self::cacheKey($cls, $k, $v), null);
+ }
+
+ function multicachenull($cls, $kv)
+ {
+ $c = self::memcache();
+ if (empty($c)) {
+ return;
+ }
+ $c->set(self::multicachekey($cls, $kv), null);
+ }
+
function &pkeyGet($cls, $kv)
{
- $i = Memcached_DataObject::multicache($cls, $kv);
+ $i = self::multicache($cls, $kv);
if ($i) {
return $i;
} else {
@@ -58,6 +78,7 @@ class Memcached_DataObject extends DB_DataObject
if ($i->find(true)) {
$i->encache();
} else {
+ self::multicachenull($cls, $kv);
$i = null;
}
return $i;
@@ -67,6 +88,9 @@ class Memcached_DataObject extends DB_DataObject
function insert()
{
$result = parent::insert();
+ if ($result) {
+ $this->encache();
+ }
return $result;
}
@@ -97,11 +121,11 @@ class Memcached_DataObject extends DB_DataObject
}
static function getcached($cls, $k, $v) {
- $c = Memcached_DataObject::memcache();
+ $c = self::memcache();
if (!$c) {
return false;
} else {
- return $c->get(Memcached_DataObject::cacheKey($cls, $k, $v));
+ return $c->get(self::cacheKey($cls, $k, $v));
}
}
@@ -168,17 +192,23 @@ class Memcached_DataObject extends DB_DataObject
function multicache($cls, $kv)
{
- ksort($kv);
- $c = Memcached_DataObject::memcache();
+ $c = self::memcache();
if (!$c) {
return false;
} else {
- $pkeys = implode(',', array_keys($kv));
- $pvals = implode(',', array_values($kv));
- return $c->get(Memcached_DataObject::cacheKey($cls, $pkeys, $pvals));
+ return $c->get(self::multicachekey($cls, $kv));
}
}
+ function multicachekey($cls, $kv)
+ {
+ ksort($kv);
+ $pkeys = implode(',', array_keys($kv));
+ $pvals = implode(',', array_values($kv));
+
+ return self::cacheKey($cls, $pkeys, $pvals);
+ }
+
function getSearchEngine($table)
{
require_once INSTALLDIR.'/lib/search_engines.php';
@@ -211,7 +241,7 @@ class Memcached_DataObject extends DB_DataObject
static function cachedQuery($cls, $qry, $expiry=3600)
{
- $c = Memcached_DataObject::memcache();
+ $c = self::memcache();
if (!$c) {
$inst = new $cls();
$inst->query($qry);