]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
Memcache returns false on cache miss
[quix0rs-gnu-social.git] / classes / Notice.php
index 7c758061515f9d2a7a959c31dce73e1ddb548658..c60237ffb0b429647a60834b80c48f98d7d65989 100644 (file)
@@ -22,9 +22,9 @@ if (!defined('LACONICA')) { exit(1); }
 /**
  * Table Definition for notice
  */
-require_once 'DB/DataObject.php';
+require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
 
-class Notice extends DB_DataObject 
+class Notice extends Memcached_DataObject 
 {
     ###START_AUTOCODE
     /* the code below is auto generated do not remove the above tag */
@@ -43,7 +43,7 @@ class Notice extends DB_DataObject
     public $source;                          // varchar(32)  
 
     /* Static get */
-    function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Notice',$k,$v); }
+    function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Notice',$k,$v); }
 
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
@@ -116,23 +116,27 @@ class Notice extends DB_DataObject
                # XXX: someone clever could prepend instead of clearing the cache
                
                if (common_config('memcached', 'enabled')) {
-                       $cache = new Memcache();
-                       if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
-                               $user = new User();
-               
-                               $user->query('SELECT id ' .
-                                                        'FROM user JOIN subscription ON user.id = subscription.subscriber ' .
-                                                        'WHERE subscription.subscribed = ' . $notice->profile_id);
-
-                               while ($user->fetch()) {
-                                       $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
-                               }
-                               
-                               $user->free();
-                               unset($user);
-                       }
+                       $notice->blowSubsCache();
                }
                
                return $notice;
        }
+       
+       function blowSubsCache() {
+               $cache = new Memcache();
+               if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
+                       $user = new User();
+                       
+                       $user->query('SELECT id ' .
+                                                'FROM user JOIN subscription ON user.id = subscription.subscriber ' .
+                                                'WHERE subscription.subscribed = ' . $this->profile_id);
+                       
+                       while ($user->fetch()) {
+                               $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
+                       }
+                       
+                       $user->free();
+                       unset($user);
+               }
+       }
 }