示例#1
0
 function blowCache()
 {
     $cache = common_memcache();
     if ($cache) {
         $cache->delete(common_cache_key('notice_tag:notice_stream:' . $this->tag));
     }
 }
示例#2
0
文件: minify.php 项目: himmelex/NTW
 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
0
 /**
  * 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
0
  -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)) {
    die("Can't initialize cache object!\n");
}
$obj = $c->get($k);
if (empty($obj)) {
    print "Empty.\n";
} else {
    var_dump($obj);
    print "\n";
}
示例#5
0
}
ini_set("max_execution_time", "0");
ini_set("max_input_time", "0");
set_time_limit(0);
mb_internal_encoding('UTF-8');
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once INSTALLDIR . '/lib/common.php';
$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;
示例#6
0
 static function memcache()
 {
     return common_memcache();
 }
示例#7
0
 function blowNoticeCount()
 {
     $c = common_memcache();
     if (!empty($c)) {
         $c->delete(common_cache_key('profile:notice_count:' . $this->id));
     }
 }
示例#8
0
 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;
 }
示例#9
0
 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);
 }
 /**
  * Update count of times we've re-encountered this message recently,
  * triggered when we get a message marked as 'redelivered'.
  *
  * Requires a CLI-friendly cache configuration.
  *
  * @param string $msgId message-id header from message
  * @return int number of retries recorded
  */
 function incDeliveryCount($msgId)
 {
     $count = 0;
     $cache = common_memcache();
     if ($cache) {
         $key = 'statusnet:stomp:message-retries:' . $msgId;
         $count = $cache->increment($key);
         if (!$count) {
             $count = 1;
             $cache->set($key, $count, null, 3600);
             $got = $cache->get($key);
         }
     }
     return $count;
 }
示例#11
0
 function setCache($attrs, $loc)
 {
     $c = common_memcache();
     if (empty($c)) {
         return null;
     }
     $key = $this->cacheKey($attrs);
     $result = $c->set($key, $loc, 0, time() + $this->expiry);
     return $result;
 }
示例#12
0
 /**
  * Reconnect to the database for each child process,
  * or they'll get very confused trying to use the
  * same socket.
  */
 protected function resetDb()
 {
     // @fixme do we need to explicitly open the db too
     // or is this implied?
     global $_DB_DATAOBJECT;
     unset($_DB_DATAOBJECT['CONNECTIONS']);
     // Reconnect main memcached, or threads will stomp on
     // each other and corrupt their requests.
     $cache = common_memcache();
     if ($cache) {
         $cache->reconnect();
     }
     // Also reconnect memcached for status_network table.
     if (!empty(Status_network::$cache)) {
         Status_network::$cache->close();
         Status_network::$cache = null;
     }
 }
示例#13
0
 function onStartStyleElement($action, &$code, &$type, &$media)
 {
     if ($this->minifyInlineCss && $type == 'text/css') {
         $c = common_memcache();
         if (!empty($c)) {
             $cacheKey = common_cache_key(self::cacheKey . ':' . crc32($code));
             $out = $c->get($cacheKey);
         }
         if (empty($out)) {
             $out = $this->minifyCss($code);
         }
         if (!empty($c)) {
             $c->set($cacheKey, $out);
         }
         if (!empty($out)) {
             $code = $out;
         }
     }
 }
示例#14
0
文件: subs.php 项目: Br3nda/laconica
function subs_unsubscribe_to($user, $other)
{
    if (!$user->isSubscribed($other)) {
        return _('Not subscribed!.');
    }
    $sub = DB_DataObject::factory('subscription');
    $sub->subscriber = $user->id;
    $sub->subscribed = $other->id;
    $sub->find(true);
    // note we checked for existence above
    if (!$sub->delete()) {
        return _('Couldn\'t delete subscription.');
    }
    $cache = common_memcache();
    if ($cache) {
        $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
    }
    return true;
}
示例#15
0
 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;
 }
示例#16
0
 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:'******'fave:ids_by_user:'******';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();
 }
示例#17
0
文件: User.php 项目: Br3nda/laconica
 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('user:faves:' . $this->id));
         $cache->delete(common_cache_key('user:faves:' . $this->id) . ';last');
     }
 }