]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
authorEvan Prodromou <evan@status.net>
Mon, 4 Jan 2010 20:55:21 +0000 (10:55 -1000)
committerEvan Prodromou <evan@status.net>
Mon, 4 Jan 2010 20:55:21 +0000 (10:55 -1000)
classes/Config.php
classes/Memcached_DataObject.php
classes/Notice.php
lib/cache.php
plugins/CacheLogPlugin.php
plugins/XCachePlugin.php

index 390d75381ac82fb74289a91fc6a77a011d875da0..6d914ca1f6e6a39b7e87c025be556c7e9a097d42 100644 (file)
@@ -59,7 +59,7 @@ class Config extends Memcached_DataObject
 
         if (!empty($c)) {
             $settings = $c->get(common_cache_key(self::settingsKey));
-            if (!empty($settings)) {
+            if ($settings !== false) {
                 return $settings;
             }
         }
index 020d813b2c4787b8a2e6439decd806e8023f9987..a77e43d38ce4e12635406c82c03abe0d02f661fd 100644 (file)
@@ -19,8 +19,6 @@
 
 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
 
-require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-
 class Memcached_DataObject extends DB_DataObject
 {
    /**
@@ -57,7 +55,7 @@ class Memcached_DataObject extends DB_DataObject
             unset($i);
         }
         $i = Memcached_DataObject::getcached($cls, $k, $v);
-        if ($i) {
+        if ($i !== false) { // false == cache miss
             return $i;
         } else {
             $i = DB_DataObject::factory($cls);
@@ -69,6 +67,12 @@ class Memcached_DataObject extends DB_DataObject
                 $i->encache();
                 return $i;
             } else {
+                // save the fact that no such row exists
+                $c = self::memcache();
+                if (!empty($c)) {
+                    $ck = self::cachekey($cls, $k, $v);
+                    $c->set($ck, null);
+                }
                 return false;
             }
         }
@@ -77,10 +81,13 @@ class Memcached_DataObject extends DB_DataObject
     function &pkeyGet($cls, $kv)
     {
         $i = Memcached_DataObject::multicache($cls, $kv);
-        if ($i) {
+        if ($i !== false) { // false == cache miss
             return $i;
         } else {
-            $i = new $cls();
+            $i = DB_DataObject::factory($cls);
+            if (empty($i)) {
+                return false;
+            }
             foreach ($kv as $k => $v) {
                 $i->$k = $v;
             }
@@ -88,6 +95,11 @@ class Memcached_DataObject extends DB_DataObject
                 $i->encache();
             } else {
                 $i = null;
+                $c = self::memcache();
+                if (!empty($c)) {
+                    $ck = self::multicacheKey($cls, $kv);
+                    $c->set($ck, null);
+                }
             }
             return $i;
         }
@@ -220,16 +232,22 @@ 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));
         }
     }
 
+    static 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';
@@ -264,7 +282,8 @@ class Memcached_DataObject extends DB_DataObject
         $key_part = common_keyize($cls).':'.md5($qry);
         $ckey = common_cache_key($key_part);
         $stored = $c->get($ckey);
-        if ($stored) {
+
+        if ($stored !== false) {
             return new ArrayWrapper($stored);
         }
 
index 3e55bd6fa5b1c6e0294730883ed551b77ad8142f..e8bc509a68700df1c196c09e6520b82cd42f6534 100644 (file)
@@ -1207,7 +1207,7 @@ class Notice extends Memcached_DataObject
 
         $idstr = $cache->get($idkey);
 
-        if (!empty($idstr)) {
+        if ($idstr !== false) {
             // Cache hit! Woohoo!
             $window = explode(',', $idstr);
             $ids = array_slice($window, $offset, $limit);
@@ -1216,7 +1216,7 @@ class Notice extends Memcached_DataObject
 
         $laststr = $cache->get($idkey.';last');
 
-        if (!empty($laststr)) {
+        if ($laststr !== false) {
             $window = explode(',', $laststr);
             $last_id = $window[0];
             $new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
@@ -1376,7 +1376,7 @@ class Notice extends Memcached_DataObject
             $ids = $this->_repeatStreamDirect($limit);
         } else {
             $idstr = $cache->get(common_cache_key('notice:repeats:'.$this->id));
-            if (!empty($idstr)) {
+            if ($idstr !== false) {
                 $ids = explode(',', $idstr);
             } else {
                 $ids = $this->_repeatStreamDirect(100);
index 253839fb17dbe75c9a9ce6751107b944099cd881..bac3499e5eed563b116c8b86a686b434cbaa72cb 100644 (file)
@@ -116,7 +116,7 @@ class Cache
 
     function get($key)
     {
-        $value = null;
+        $value = false;
 
         if (Event::handle('StartCacheGet', array(&$key, &$value))) {
             if (array_key_exists($key, $this->_items)) {
index 9eb04641e6b2ba24e1c77e300b449e47feb1388b..f1e5dd83aa2c7931fb8c4e1aa14bb6a90d3eb14c 100644 (file)
@@ -61,7 +61,7 @@ class CacheLogPlugin extends Plugin
 
     function onEndCacheGet($key, &$value)
     {
-        if (is_null($value)) {
+        if ($value === false) {
             $this->log(LOG_INFO, "Cache MISS for key '$key'");
         } else {
             $this->log(LOG_INFO, "Cache HIT for key '$key'");
@@ -71,7 +71,21 @@ class CacheLogPlugin extends Plugin
 
     function onStartCacheSet(&$key, &$value, &$flag, &$expiry, &$success)
     {
-        $this->log(LOG_INFO, "Setting cache value for key '$key'");
+        if (empty($value)) {
+            if (is_array($value)) {
+                $this->log(LOG_INFO, "Setting empty array for key '$key'");
+            } else if (is_null($value)) {
+                $this->log(LOG_INFO, "Setting null value for key '$key'");
+            } else if (is_string($value)) {
+                $this->log(LOG_INFO, "Setting empty string for key '$key'");
+            } else if (is_integer($value)) {
+                $this->log(LOG_INFO, "Setting integer 0 for key '$key'");
+            } else {
+                $this->log(LOG_INFO, "Setting empty value '$value' for key '$key'");
+            }
+        } else {
+            $this->log(LOG_INFO, "Setting non-empty value for key '$key'");
+        }
         return true;
     }
 
index 8eed12cbc9f28ae6f388a2a6fdb042b37906d539..03cb0c06ea94cc54a8e3605a94932b291ef0176f 100644 (file)
@@ -63,8 +63,10 @@ class XCachePlugin extends Plugin
 
     function onStartCacheGet(&$key, &$value)
     {
-        $value = xcache_get($key);
-        if (!is_null($value)) {
+        if (!xcache_isset($key)) {
+            $value = false;
+        } else {
+            $value = xcache_get($key);
             $value = unserialize($value);
         }
         Event::handle('EndCacheGet', array($key, &$value));