]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
move memcache connections to util.php
authorEvan Prodromou <evan@controlyourself.ca>
Fri, 26 Sep 2008 20:01:02 +0000 (16:01 -0400)
committerEvan Prodromou <evan@controlyourself.ca>
Fri, 26 Sep 2008 20:01:02 +0000 (16:01 -0400)
darcs-hash:20080926200102-5ed1f-debbc18981424d7724277ac82e5fbfd5e797090e.gz

classes/Memcached_DataObject.php
classes/Notice.php
classes/User.php
lib/util.php

index 7ca2c7db210a774652fd172ce49cb1a3d8a914c8..84529ce9a6e7c5eb43dd45d3e293ff8c86f91b0d 100644 (file)
@@ -69,20 +69,7 @@ class Memcached_DataObject extends DB_DataObject
        }
        
        static function memcache() {
-               if (!common_config('memcached', 'enabled')) {
-                       return NULL;
-               } else {
-                       $cache = new Memcache();
-                       $servers = common_config('memcached', 'server');
-                       if (is_array($servers)) {
-                               foreach($servers as $server) {
-                                       $cache->addServer($server);
-                               }
-                       } else {
-                                       $cache->addServer($servers);
-                       }
-                       return $cache;
-               }
+               return common_memcache();
        }
        
        static function cacheKey($cls, $k, $v) {
index f3debe742026695b5b1388c8a177d0f0b31de0af..b42a8726e36dd7da9a0cf2e603b14b10669f62b5 100644 (file)
@@ -125,8 +125,8 @@ class Notice extends Memcached_DataObject
        }
        
        function blowSubsCache() {
-               $cache = new Memcache();
-               if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
+               $cache = common_memcache();
+               if ($cache) {
                        $user = new User();
                        
                        $user->query('SELECT id ' .
index 94fcff9c8e6c89370d2b28bc4bf11bd52200c57c..de260035abb3254a1bba2f0029d5f44fade25095 100644 (file)
@@ -196,10 +196,9 @@ class User extends Memcached_DataObject
 
        function noticesWithFriendsWindow() {
                
-               $cache = new Memcache();
-               $res = $cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'));
+               $cache = common_memcache();
                
-               if (!$res) {
+               if (!$cache) {
                        return NULL;
                }
                
index 621fdc1371ee13aeda04e9bd954bd380519e9fde..20fe4ced67d0c1494aed61549a81775e0a64ee2b 100644 (file)
@@ -1727,4 +1727,24 @@ function common_message_form($content, $user, $to) {
        
        common_element_end('p');
        common_element_end('form');
-}
\ No newline at end of file
+}
+
+function common_memcache() {
+       static $cache = NULL;
+       if (!common_config('memcached', 'enabled')) {
+               return NULL;
+       } else {
+               if (!$cache) {
+                       $cache = new Memcache();
+                       $servers = common_config('memcached', 'server');
+                       if (is_array($servers)) {
+                               foreach($servers as $server) {
+                                       $cache->addServer($server);
+                               }
+                       } else {
+                               $cache->addServer($servers);
+                       }
+               }
+               return $cache;
+       }
+}