本文整理汇总了PHP中common_cache_key函数的典型用法代码示例。如果您正苦于以下问题:PHP common_cache_key函数的具体用法?PHP common_cache_key怎么用?PHP common_cache_key使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了common_cache_key函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: blowCache
function blowCache()
{
$cache = common_memcache();
if ($cache) {
$cache->delete(common_cache_key('notice_tag:notice_stream:' . $this->tag));
}
}
示例2: handle
function handle($args)
{
parent::handle($args);
$c = common_memcache();
if (!empty($c)) {
$cacheKey = common_cache_key(MinifyPlugin::cacheKey . ':' . $this->file . '?v=' . empty($this->v) ? '' : $this->v);
$out = $c->get($cacheKey);
}
if (empty($out)) {
$out = $this->minify($this->file);
}
if (!empty($c)) {
$c->set($cacheKey, $out);
}
$sec = session_cache_expire() * 60;
header('Cache-Control: public, max-age=' . $sec);
header('Pragma: public');
$this->raw($out);
}
示例3: etag
/**
* etag for file
*
* This returns the same data (inode, size, mtime) as Apache would,
* but in decimal instead of hex.
*
* @return string etag http header
*/
function etag()
{
if (common_config('site', 'use_x_sendfile')) {
return null;
}
$cache = common_memcache();
if ($cache) {
$key = common_cache_key('attachments:etag:' . $this->path);
$etag = $cache->get($key);
if ($etag === false) {
$etag = crc32(file_get_contents($this->path));
$cache->set($key, $etag);
}
return $etag;
}
$stat = stat($this->path);
return '"' . $stat['ino'] . '-' . $stat['size'] . '-' . $stat['mtime'] . '"';
}
示例4: cacheSet
static function cacheSet($keyPart, $value)
{
$c = self::memcache();
if (empty($c)) {
return false;
}
$cacheKey = common_cache_key($keyPart);
return $c->set($cacheKey, $value);
}
示例5: common_log
$start_at = $argc > 1 ? $argv[1] : null;
common_log(LOG_INFO, 'Updating user inboxes.');
$user = new User();
if ($start_at) {
$user->whereAdd('id >= ' . $start_at);
}
$cnt = $user->find();
$cache = common_memcache();
while ($user->fetch()) {
common_log(LOG_INFO, 'Updating inbox for user ' . $user->id);
$user->query('BEGIN');
$inbox = new Notice_inbox();
$result = $inbox->query('INSERT LOW_PRIORITY INTO notice_inbox (user_id, notice_id, created) ' . 'SELECT ' . $user->id . ', notice.id, notice.created ' . 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' . 'WHERE subscription.subscriber = ' . $user->id . ' ' . 'AND notice.created >= subscription.created ' . 'AND NOT EXISTS (SELECT user_id, notice_id ' . 'FROM notice_inbox ' . 'WHERE user_id = ' . $user->id . ' ' . 'AND notice_id = notice.id)');
if (is_null($result) || $result === false) {
common_log_db_error($inbox, 'INSERT', __FILE__);
continue;
}
$orig = clone $user;
$user->inboxed = 1;
$result = $user->update($orig);
if (!$result) {
common_log_db_error($user, 'UPDATE', __FILE__);
continue;
}
$user->query('COMMIT');
$inbox->free();
unset($inbox);
if ($cache) {
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
}
}
示例6: define
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
$shortoptions = "t:c:v:k:";
$helptext = <<<ENDOFHELP
USAGE: showcache.php <args>
shows the cached object based on the args
-t table Table to look up
-c column Column to look up, default "id"
-v value Value to look up
-k key Key to look up; other args are ignored
ENDOFHELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
$karg = get_option_value('k');
if (!empty($karg)) {
$k = common_cache_key($karg);
} else {
$table = get_option_value('t');
if (empty($table)) {
die("No table or key specified\n");
}
$column = get_option_value('c');
if (empty($column)) {
$column = 'id';
}
$value = get_option_value('v');
$k = Memcached_DataObject::cacheKey($table, $column, $value);
}
print "Checking key '{$k}'...\n";
$c = common_memcache();
if (empty($c)) {
示例7: cachedQuery
static function cachedQuery($cls, $qry, $expiry = 3600)
{
$c = Memcached_DataObject::memcache();
if (!$c) {
$inst = new $cls();
$inst->query($qry);
return $inst;
}
$key_part = common_keyize($cls) . ':' . md5($qry);
$ckey = common_cache_key($key_part);
$stored = $c->get($ckey);
if ($stored) {
return new ArrayWrapper($stored);
}
$inst = new $cls();
$inst->query($qry);
$cached = array();
while ($inst->fetch()) {
$cached[] = clone $inst;
}
$inst->free();
$c->set($ckey, $cached, MEMCACHE_COMPRESSED, $expiry);
return new ArrayWrapper($cached);
}
示例8: _blowSettingsCache
function _blowSettingsCache()
{
$c = self::memcache();
if (!empty($c)) {
$c->delete(common_cache_key(self::settingsKey));
}
}
示例9: getCachedStream
static function getCachedStream($qry, $cachekey, $offset, $limit, $order)
{
# If outside our cache window, just go to the DB
if ($offset + $limit > NOTICE_CACHE_WINDOW) {
return Notice::getStreamDirect($qry, $offset, $limit, null, null, $order, null);
}
# Get the cache; if we can't, just go to the DB
$cache = common_memcache();
if (!$cache) {
return Notice::getStreamDirect($qry, $offset, $limit, null, null, $order, null);
}
# Get the notices out of the cache
$notices = $cache->get(common_cache_key($cachekey));
# On a cache hit, return a DB-object-like wrapper
if ($notices !== false) {
$wrapper = new ArrayWrapper(array_slice($notices, $offset, $limit));
return $wrapper;
}
# If the cache was invalidated because of new data being
# added, we can try and just get the new stuff. We keep an additional
# copy of the data at the key + ';last'
# No cache hit. Try to get the *last* cached version
$last_notices = $cache->get(common_cache_key($cachekey) . ';last');
if ($last_notices) {
# Reverse-chron order, so last ID is last.
$last_id = $last_notices[0]->id;
# XXX: this assumes monotonically increasing IDs; a fair
# bet with our DB.
$new_notice = Notice::getStreamDirect($qry, 0, NOTICE_CACHE_WINDOW, $last_id, null, $order, null);
if ($new_notice) {
$new_notices = array();
while ($new_notice->fetch()) {
$new_notices[] = clone $new_notice;
}
$new_notice->free();
$notices = array_slice(array_merge($new_notices, $last_notices), 0, NOTICE_CACHE_WINDOW);
# Store the array in the cache for next time
$result = $cache->set(common_cache_key($cachekey), $notices);
$result = $cache->set(common_cache_key($cachekey) . ';last', $notices);
# return a wrapper of the array for use now
return new ArrayWrapper(array_slice($notices, $offset, $limit));
}
}
# Otherwise, get the full cache window out of the DB
$notice = Notice::getStreamDirect($qry, 0, NOTICE_CACHE_WINDOW, null, null, $order, null);
# If there are no hits, just return the value
if (!$notice) {
return $notice;
}
# Pack results into an array
$notices = array();
while ($notice->fetch()) {
$notices[] = clone $notice;
}
$notice->free();
# Store the array in the cache for next time
$result = $cache->set(common_cache_key($cachekey), $notices);
$result = $cache->set(common_cache_key($cachekey) . ';last', $notices);
# return a wrapper of the array for use now
$wrapper = new ArrayWrapper(array_slice($notices, $offset, $limit));
return $wrapper;
}
示例10: blowNoticeCount
function blowNoticeCount()
{
$c = common_memcache();
if (!empty($c)) {
$c->delete(common_cache_key('profile:notice_count:' . $this->id));
}
}
示例11: blowFavesCache
function blowFavesCache()
{
$cache = common_memcache();
if ($cache) {
// Faves don't happen chronologically, so we need to blow
// ;last cache, too
$cache->delete(common_cache_key('fave:ids_by_user:' . $this->id));
$cache->delete(common_cache_key('fave:ids_by_user:' . $this->id . ';last'));
$cache->delete(common_cache_key('fave:ids_by_user_own:' . $this->id));
$cache->delete(common_cache_key('fave:ids_by_user_own:' . $this->id . ';last'));
}
$profile = $this->getProfile();
$profile->blowFaveCount();
}
示例12: get_ldap_connection
function get_ldap_connection($config = null)
{
if ($config == null) {
$config = $this->ldap_config;
}
$config_id = crc32(serialize($config));
if (array_key_exists($config_id, self::$ldap_connections)) {
$ldap = self::$ldap_connections[$config_id];
} else {
//cannot use Net_LDAP2::connect() as StatusNet uses
//PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
//PEAR handling can be overridden on instance objects, so we do that.
$ldap = new Net_LDAP2($config);
$ldap->setErrorHandling(PEAR_ERROR_RETURN);
$err = $ldap->bind();
if (Net_LDAP2::isError($err)) {
// if we were called with a config, assume caller will handle
// incorrect username/password (LDAP_INVALID_CREDENTIALS)
if (isset($config) && $err->getCode() == 0x31) {
throw new LdapInvalidCredentialsException('Could not connect to LDAP server: ' . $err->getMessage());
}
throw new Exception('Could not connect to LDAP server: ' . $err->getMessage());
}
$c = common_memcache();
if (!empty($c)) {
$cacheObj = new MemcacheSchemaCache(array('c' => $c, 'cacheKey' => common_cache_key('ldap_schema:' . $config_id)));
$ldap->registerSchemaCache($cacheObj);
}
self::$ldap_connections[$config_id] = $ldap;
}
return $ldap;
}
示例13: repeatStream
function repeatStream($limit = 100)
{
$cache = common_memcache();
if (empty($cache)) {
$ids = $this->_repeatStreamDirect($limit);
} else {
$idstr = $cache->get(common_cache_key('notice:repeats:' . $this->id));
if ($idstr !== false) {
$ids = explode(',', $idstr);
} else {
$ids = $this->_repeatStreamDirect(100);
$cache->set(common_cache_key('notice:repeats:' . $this->id), implode(',', $ids));
}
if ($limit < 100) {
// We do a max of 100, so slice down to limit
$ids = array_slice($ids, 0, $limit);
}
}
return Notice::getStreamByIds($ids);
}
示例14: define
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
$helptext = <<<ENDOFHELP
uncache_users.php <idfile>
Uncache users listed in an ID file, default 'ids.txt'.
ENDOFHELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
$id_file = count($args) > 1 ? $args[0] : 'ids.txt';
common_log(LOG_INFO, 'Updating user inboxes.');
$ids = file($id_file);
$memc = common_memcache();
foreach ($ids as $id) {
$user = User::staticGet('id', $id);
if (!$user) {
common_log(LOG_WARNING, 'No such user: ' . $id);
continue;
}
$user->decache();
$memc->delete(common_cache_key('user:notices_with_friends:' . $user->id));
$memc->delete(common_cache_key('user:notices_with_friends:' . $user->id . ';last'));
}
示例15: cacheKey
function cacheKey($attrs)
{
$key = 'geonames:' . implode(',', array_keys($attrs)) . ':' . common_keyize(implode(',', array_values($attrs)));
if ($this->cachePrefix) {
return $this->cachePrefix . ':' . $key;
} else {
return common_cache_key($key);
}
}