common_cache_key() -> Cache::key()

This commit is contained in:
Evan Prodromou 2010-09-06 10:07:43 -04:00
parent e42d2124a3
commit a319b40c97
15 changed files with 40 additions and 45 deletions

View File

@ -131,7 +131,7 @@ class GetfileAction extends Action
$cache = Cache::instance(); $cache = Cache::instance();
if($cache) { if($cache) {
$key = common_cache_key('attachments:etag:' . $this->path); $key = Cache::key('attachments:etag:' . $this->path);
$etag = $cache->get($key); $etag = $cache->get($key);
if($etag === false) { if($etag === false) {
$etag = crc32(file_get_contents($this->path)); $etag = crc32(file_get_contents($this->path));

View File

@ -58,7 +58,7 @@ class Config extends Memcached_DataObject
$c = self::memcache(); $c = self::memcache();
if (!empty($c)) { if (!empty($c)) {
$settings = $c->get(common_cache_key(self::settingsKey)); $settings = $c->get(Cache::key(self::settingsKey));
if ($settings !== false) { if ($settings !== false) {
return $settings; return $settings;
} }
@ -77,7 +77,7 @@ class Config extends Memcached_DataObject
$config->free(); $config->free();
if (!empty($c)) { if (!empty($c)) {
$c->set(common_cache_key(self::settingsKey), $settings); $c->set(Cache::key(self::settingsKey), $settings);
} }
return $settings; return $settings;
@ -154,7 +154,7 @@ class Config extends Memcached_DataObject
$c = self::memcache(); $c = self::memcache();
if (!empty($c)) { if (!empty($c)) {
$c->delete(common_cache_key(self::settingsKey)); $c->delete(Cache::key(self::settingsKey));
} }
} }
} }

View File

@ -134,7 +134,7 @@ class Memcached_DataObject extends Safe_DataObject
str_replace("\n", " ", $e->getTraceAsString())); str_replace("\n", " ", $e->getTraceAsString()));
} }
$vstr = self::valueString($v); $vstr = self::valueString($v);
return common_cache_key(strtolower($cls).':'.$k.':'.$vstr); return Cache::key(strtolower($cls).':'.$k.':'.$vstr);
} }
static function getcached($cls, $k, $v) { static function getcached($cls, $k, $v) {
@ -303,7 +303,7 @@ class Memcached_DataObject extends Safe_DataObject
return $inst; return $inst;
} }
$key_part = Cache::keyize($cls).':'.md5($qry); $key_part = Cache::keyize($cls).':'.md5($qry);
$ckey = common_cache_key($key_part); $ckey = Cache::key($key_part);
$stored = $c->get($ckey); $stored = $c->get($ckey);
if ($stored !== false) { if ($stored !== false) {
@ -550,7 +550,7 @@ class Memcached_DataObject extends Safe_DataObject
$keyPart = vsprintf($format, $args); $keyPart = vsprintf($format, $args);
$cacheKey = common_cache_key($keyPart); $cacheKey = Cache::key($keyPart);
return $c->delete($cacheKey); return $c->delete($cacheKey);
} }
@ -592,7 +592,7 @@ class Memcached_DataObject extends Safe_DataObject
return false; return false;
} }
$cacheKey = common_cache_key($keyPart); $cacheKey = Cache::key($keyPart);
return $c->get($cacheKey); return $c->get($cacheKey);
} }
@ -605,7 +605,7 @@ class Memcached_DataObject extends Safe_DataObject
return false; return false;
} }
$cacheKey = common_cache_key($keyPart); $cacheKey = Cache::key($keyPart);
return $c->set($cacheKey, $value, $flag, $expiry); return $c->set($cacheKey, $value, $flag, $expiry);
} }

View File

@ -759,7 +759,7 @@ class Notice extends Memcached_DataObject
$c = self::memcache(); $c = self::memcache();
if (!empty($c)) { if (!empty($c)) {
$ni = $c->get(common_cache_key('notice:who_gets:'.$this->id)); $ni = $c->get(Cache::key('notice:who_gets:'.$this->id));
if ($ni !== false) { if ($ni !== false) {
return $ni; return $ni;
} }
@ -811,7 +811,7 @@ class Notice extends Memcached_DataObject
if (!empty($c)) { if (!empty($c)) {
// XXX: pack this data better // XXX: pack this data better
$c->set(common_cache_key('notice:who_gets:'.$this->id), $ni); $c->set(Cache::key('notice:who_gets:'.$this->id), $ni);
} }
return $ni; return $ni;
@ -1595,7 +1595,7 @@ class Notice extends Memcached_DataObject
$max_id))); $max_id)));
} }
$idkey = common_cache_key($cachekey); $idkey = Cache::key($cachekey);
$idstr = $cache->get($idkey); $idstr = $cache->get($idkey);
@ -1782,12 +1782,12 @@ class Notice extends Memcached_DataObject
if (empty($cache)) { if (empty($cache)) {
$ids = $this->_repeatStreamDirect($limit); $ids = $this->_repeatStreamDirect($limit);
} else { } else {
$idstr = $cache->get(common_cache_key('notice:repeats:'.$this->id)); $idstr = $cache->get(Cache::key('notice:repeats:'.$this->id));
if ($idstr !== false) { if ($idstr !== false) {
$ids = explode(',', $idstr); $ids = explode(',', $idstr);
} else { } else {
$ids = $this->_repeatStreamDirect(100); $ids = $this->_repeatStreamDirect(100);
$cache->set(common_cache_key('notice:repeats:'.$this->id), implode(',', $ids)); $cache->set(Cache::key('notice:repeats:'.$this->id), implode(',', $ids));
} }
if ($limit < 100) { if ($limit < 100) {
// We do a max of 100, so slice down to limit // We do a max of 100, so slice down to limit

View File

@ -432,7 +432,7 @@ class Profile extends Memcached_DataObject
$c = Cache::instance(); $c = Cache::instance();
if (!empty($c)) { if (!empty($c)) {
$cnt = $c->get(common_cache_key('profile:subscription_count:'.$this->id)); $cnt = $c->get(Cache::key('profile:subscription_count:'.$this->id));
if (is_integer($cnt)) { if (is_integer($cnt)) {
return (int) $cnt; return (int) $cnt;
} }
@ -446,7 +446,7 @@ class Profile extends Memcached_DataObject
$cnt = ($cnt > 0) ? $cnt - 1 : $cnt; $cnt = ($cnt > 0) ? $cnt - 1 : $cnt;
if (!empty($c)) { if (!empty($c)) {
$c->set(common_cache_key('profile:subscription_count:'.$this->id), $cnt); $c->set(Cache::key('profile:subscription_count:'.$this->id), $cnt);
} }
return $cnt; return $cnt;
@ -456,7 +456,7 @@ class Profile extends Memcached_DataObject
{ {
$c = Cache::instance(); $c = Cache::instance();
if (!empty($c)) { if (!empty($c)) {
$cnt = $c->get(common_cache_key('profile:subscriber_count:'.$this->id)); $cnt = $c->get(Cache::key('profile:subscriber_count:'.$this->id));
if (is_integer($cnt)) { if (is_integer($cnt)) {
return (int) $cnt; return (int) $cnt;
} }
@ -468,7 +468,7 @@ class Profile extends Memcached_DataObject
$cnt = (int) $sub->count('distinct subscriber'); $cnt = (int) $sub->count('distinct subscriber');
if (!empty($c)) { if (!empty($c)) {
$c->set(common_cache_key('profile:subscriber_count:'.$this->id), $cnt); $c->set(Cache::key('profile:subscriber_count:'.$this->id), $cnt);
} }
return $cnt; return $cnt;
@ -478,7 +478,7 @@ class Profile extends Memcached_DataObject
{ {
$c = Cache::instance(); $c = Cache::instance();
if (!empty($c)) { if (!empty($c)) {
$cnt = $c->get(common_cache_key('profile:fave_count:'.$this->id)); $cnt = $c->get(Cache::key('profile:fave_count:'.$this->id));
if (is_integer($cnt)) { if (is_integer($cnt)) {
return (int) $cnt; return (int) $cnt;
} }
@ -489,7 +489,7 @@ class Profile extends Memcached_DataObject
$cnt = (int) $faves->count('distinct notice_id'); $cnt = (int) $faves->count('distinct notice_id');
if (!empty($c)) { if (!empty($c)) {
$c->set(common_cache_key('profile:fave_count:'.$this->id), $cnt); $c->set(Cache::key('profile:fave_count:'.$this->id), $cnt);
} }
return $cnt; return $cnt;
@ -500,7 +500,7 @@ class Profile extends Memcached_DataObject
$c = Cache::instance(); $c = Cache::instance();
if (!empty($c)) { if (!empty($c)) {
$cnt = $c->get(common_cache_key('profile:notice_count:'.$this->id)); $cnt = $c->get(Cache::key('profile:notice_count:'.$this->id));
if (is_integer($cnt)) { if (is_integer($cnt)) {
return (int) $cnt; return (int) $cnt;
} }
@ -511,7 +511,7 @@ class Profile extends Memcached_DataObject
$cnt = (int) $notices->count('distinct id'); $cnt = (int) $notices->count('distinct id');
if (!empty($c)) { if (!empty($c)) {
$c->set(common_cache_key('profile:notice_count:'.$this->id), $cnt); $c->set(Cache::key('profile:notice_count:'.$this->id), $cnt);
} }
return $cnt; return $cnt;
@ -521,7 +521,7 @@ class Profile extends Memcached_DataObject
{ {
$c = Cache::instance(); $c = Cache::instance();
if (!empty($c)) { if (!empty($c)) {
$c->delete(common_cache_key('profile:subscriber_count:'.$this->id)); $c->delete(Cache::key('profile:subscriber_count:'.$this->id));
} }
} }
@ -529,7 +529,7 @@ class Profile extends Memcached_DataObject
{ {
$c = Cache::instance(); $c = Cache::instance();
if (!empty($c)) { if (!empty($c)) {
$c->delete(common_cache_key('profile:subscription_count:'.$this->id)); $c->delete(Cache::key('profile:subscription_count:'.$this->id));
} }
} }
@ -537,7 +537,7 @@ class Profile extends Memcached_DataObject
{ {
$c = Cache::instance(); $c = Cache::instance();
if (!empty($c)) { if (!empty($c)) {
$c->delete(common_cache_key('profile:fave_count:'.$this->id)); $c->delete(Cache::key('profile:fave_count:'.$this->id));
} }
} }
@ -545,7 +545,7 @@ class Profile extends Memcached_DataObject
{ {
$c = Cache::instance(); $c = Cache::instance();
if (!empty($c)) { if (!empty($c)) {
$c->delete(common_cache_key('profile:notice_count:'.$this->id)); $c->delete(Cache::key('profile:notice_count:'.$this->id));
} }
} }

View File

@ -491,10 +491,10 @@ class User extends Memcached_DataObject
if ($cache) { if ($cache) {
// Faves don't happen chronologically, so we need to blow // Faves don't happen chronologically, so we need to blow
// ;last cache, too // ;last cache, too
$cache->delete(common_cache_key('fave:ids_by_user:'.$this->id)); $cache->delete(Cache::key('fave:ids_by_user:'.$this->id));
$cache->delete(common_cache_key('fave:ids_by_user:'.$this->id.';last')); $cache->delete(Cache::key('fave:ids_by_user:'.$this->id.';last'));
$cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id)); $cache->delete(Cache::key('fave:ids_by_user_own:'.$this->id));
$cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id.';last')); $cache->delete(Cache::key('fave:ids_by_user_own:'.$this->id.';last'));
} }
$profile = $this->getProfile(); $profile = $this->getProfile();
$profile->blowFaveCount(); $profile->blowFaveCount();

View File

@ -1793,11 +1793,6 @@ function common_session_token()
return $_SESSION['token']; return $_SESSION['token'];
} }
function common_cache_key($extra)
{
return Cache::key($extra);
}
function common_license_terms($uri) function common_license_terms($uri)
{ {
if(preg_match('/creativecommons.org\/licenses\/([^\/]+)/', $uri, $matches)) { if(preg_match('/creativecommons.org\/licenses\/([^\/]+)/', $uri, $matches)) {

View File

@ -420,7 +420,7 @@ class GeonamesPlugin extends Plugin
if ($this->cachePrefix) { if ($this->cachePrefix) {
return $this->cachePrefix . ':' . $key; return $this->cachePrefix . ':' . $key;
} else { } else {
return common_cache_key($key); return Cache::key($key);
} }
} }

View File

@ -130,7 +130,7 @@ class LdapCommon
if (!empty($c)) { if (!empty($c)) {
$cacheObj = new MemcacheSchemaCache( $cacheObj = new MemcacheSchemaCache(
array('c'=>$c, array('c'=>$c,
'cacheKey' => common_cache_key('ldap_schema:' . $config_id))); 'cacheKey' => Cache::key('ldap_schema:' . $config_id)));
$ldap->registerSchemaCache($cacheObj); $ldap->registerSchemaCache($cacheObj);
} }
self::$ldap_connections[$config_id] = $ldap; self::$ldap_connections[$config_id] = $ldap;

View File

@ -121,7 +121,7 @@ class MinifyPlugin extends Plugin
if($this->minifyInlineJs && $type=='text/javascript'){ if($this->minifyInlineJs && $type=='text/javascript'){
$c = Cache::instance(); $c = Cache::instance();
if (!empty($c)) { if (!empty($c)) {
$cacheKey = common_cache_key(self::cacheKey . ':' . crc32($code)); $cacheKey = Cache::key(self::cacheKey . ':' . crc32($code));
$out = $c->get($cacheKey); $out = $c->get($cacheKey);
} }
if(empty($out)) { if(empty($out)) {
@ -141,7 +141,7 @@ class MinifyPlugin extends Plugin
if($this->minifyInlineCss && $type=='text/css'){ if($this->minifyInlineCss && $type=='text/css'){
$c = Cache::instance(); $c = Cache::instance();
if (!empty($c)) { if (!empty($c)) {
$cacheKey = common_cache_key(self::cacheKey . ':' . crc32($code)); $cacheKey = Cache::key(self::cacheKey . ':' . crc32($code));
$out = $c->get($cacheKey); $out = $c->get($cacheKey);
} }
if(empty($out)) { if(empty($out)) {

View File

@ -76,7 +76,7 @@ class MinifyAction extends Action
$c = Cache::instance(); $c = Cache::instance();
if (!empty($c)) { if (!empty($c)) {
$cacheKey = common_cache_key(MinifyPlugin::cacheKey . ':' . $this->file . '?v=' . empty($this->v)?'':$this->v); $cacheKey = Cache::key(MinifyPlugin::cacheKey . ':' . $this->file . '?v=' . empty($this->v)?'':$this->v);
$out = $c->get($cacheKey); $out = $c->get($cacheKey);
} }
if(empty($out)) { if(empty($out)) {

View File

@ -38,7 +38,7 @@ require_once INSTALLDIR.'/scripts/commandline.inc';
$karg = get_option_value('k', 'key'); $karg = get_option_value('k', 'key');
if (!empty($karg)) { if (!empty($karg)) {
$k = common_cache_key($karg); $k = Cache::key($karg);
} else { } else {
$table = get_option_value('t', 'table'); $table = get_option_value('t', 'table');
if (empty($table)) { if (empty($table)) {

View File

@ -76,6 +76,6 @@ while ($user->fetch()) {
$inbox->free(); $inbox->free();
unset($inbox); unset($inbox);
if ($cache) { if ($cache) {
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); $cache->delete(Cache::key('user:notices_with_friends:' . $user->id));
} }
} }

View File

@ -38,7 +38,7 @@ require_once INSTALLDIR.'/scripts/commandline.inc';
$karg = get_option_value('k'); $karg = get_option_value('k');
if (!empty($karg)) { if (!empty($karg)) {
$k = common_cache_key($karg); $k = Cache::key($karg);
} else { } else {
$table = get_option_value('t'); $table = get_option_value('t');
if (empty($table)) { if (empty($table)) {

View File

@ -47,6 +47,6 @@ foreach ($ids as $id) {
$user->decache(); $user->decache();
$memc->delete(common_cache_key('user:notices_with_friends:'. $user->id)); $memc->delete(Cache::key('user:notices_with_friends:'. $user->id));
$memc->delete(common_cache_key('user:notices_with_friends:'. $user->id . ';last')); $memc->delete(Cache::key('user:notices_with_friends:'. $user->id . ';last'));
} }