}
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) {
}
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 ' .
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;
}
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;
+ }
+}