本文整理汇总了PHP中Cache::key方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::key方法的具体用法?PHP Cache::key怎么用?PHP Cache::key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
public static function set($type, $id, $object)
{
$loc = CacheLocal::get();
if (!$loc->enabled) {
return false;
}
$key = Cache::key($type, $id);
if (is_object($object)) {
$r = clone $object;
} else {
$r = $object;
}
$loc->cache[$key] = $r;
}
示例2: getNoticeIds
function getNoticeIds($offset, $limit, $sinceId, $maxId)
{
$cache = Cache::instance();
// We cache self::CACHE_WINDOW elements at the tip of the stream.
// If the cache won't be hit, just generate directly.
if (empty($cache) || $sinceId != 0 || $maxId != 0 || is_null($limit) || $offset + $limit > self::CACHE_WINDOW) {
return $this->stream->getNoticeIds($offset, $limit, $sinceId, $maxId);
}
// Check the cache to see if we have the stream.
$idkey = Cache::key($this->cachekey);
$idstr = $cache->get($idkey);
if ($idstr !== false) {
// Cache hit! Woohoo!
$window = explode(',', $idstr);
$ids = array_slice($window, $offset, $limit);
return $ids;
}
if ($this->useLast) {
// Check the cache to see if we have a "last-known-good" version.
// The actual cache gets blown away when new notices are added, but
// the "last" value holds a lot of info. We might need to only generate
// a few at the "tip", which can bound our queries and save lots
// of time.
$laststr = $cache->get($idkey . ';last');
if ($laststr !== false) {
$window = explode(',', $laststr);
$last_id = $window[0];
$new_ids = $this->stream->getNoticeIds(0, self::CACHE_WINDOW, $last_id, 0);
$new_window = array_merge($new_ids, $window);
$new_windowstr = implode(',', $new_window);
$result = $cache->set($idkey, $new_windowstr);
$result = $cache->set($idkey . ';last', $new_windowstr);
$ids = array_slice($new_window, $offset, $limit);
return $ids;
}
}
// No cache hits :( Generate directly and stick the results
// into the cache. Note we generate the full cache window.
$window = $this->stream->getNoticeIds(0, self::CACHE_WINDOW, 0, 0);
$windowstr = implode(',', $window);
$result = $cache->set($idkey, $windowstr);
if ($this->useLast) {
$result = $cache->set($idkey . ';last', $windowstr);
}
// Return just the slice that was requested
$ids = array_slice($window, $offset, $limit);
return $ids;
}
示例3: handle
function handle($args)
{
parent::handle($args);
$c = Cache::instance();
if (!empty($c)) {
$cacheKey = 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);
}
示例4: getFavesCount
static function getFavesCount($notice_id)
{
$c = Cache::instance();
if (!empty($c)) {
$cnt = $c->get(Cache::key('notice:favorites_count:' . $notice_id));
if (is_integer($cnt)) {
return (int) $cnt;
}
}
$original = Notice::staticGet('id', $notice_id);
$cnt = $original->favorites_count;
if (!empty($c)) {
$c->set(Cache::key('notice:favorites_count:' . $notice_id), $cnt);
}
return empty($cnt) ? 0 : $cnt;
}
示例5: cacheSet
static function cacheSet($keyPart, $value, $flag = null, $expiry = null)
{
$c = self::memcache();
if (empty($c)) {
return false;
}
$cacheKey = Cache::key($keyPart);
return $c->set($cacheKey, $value, $flag, $expiry);
}
示例6: onStartStyleElement
function onStartStyleElement($action, &$code, &$type, &$media)
{
if ($this->minifyInlineCss && $type == 'text/css') {
$c = Cache::instance();
if (!empty($c)) {
$cacheKey = 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;
}
}
}
示例7: getNotices
function getNotices($y, $m, $d, $i)
{
$n = Notice::cacheGet("sitemap:notice:{$y}:{$m}:{$d}:{$i}");
if ($n === false) {
$notice = new Notice();
$begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
// XXX: estimates 1d == 24h, which screws up days
// with leap seconds (1d == 24h + 1s). Thankfully they're
// few and far between.
$theend = strtotime($begindt) + 24 * 60 * 60;
$enddt = common_sql_date($theend);
$notice->selectAdd();
$notice->selectAdd('id, created');
$notice->whereAdd("created >= '{$begindt}'");
$notice->whereAdd("created < '{$enddt}'");
$notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
$notice->orderBy('created');
$offset = ($i - 1) * SitemapPlugin::NOTICES_PER_MAP;
$limit = SitemapPlugin::NOTICES_PER_MAP;
$notice->limit($offset, $limit);
$notice->find();
$n = array();
while ($notice->fetch()) {
$n[] = array($notice->id, $notice->created);
}
$c = Cache::instance();
if (!empty($c)) {
$c->set(Cache::key("sitemap:notice:{$y}:{$m}:{$d}:{$i}"), $n, Cache::COMPRESSED, time() > $theend ? time() + 90 * 24 * 60 * 60 : time() + 5 * 60);
}
}
return $n;
}
示例8: 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 = Cache::instance();
foreach ($ids as $id) {
$user = User::staticGet('id', $id);
if (!$user) {
common_log(LOG_WARNING, 'No such user: ' . $id);
continue;
}
$user->decache();
$memc->delete(Cache::key('user:notices_with_friends:' . $user->id));
$memc->delete(Cache::key('user:notices_with_friends:' . $user->id . ';last'));
}
示例9: getUsers
function getUsers($y, $m, $d, $i)
{
$u = User::cacheGet("sitemap:user:{$y}:{$m}:{$d}:{$i}");
if ($u === false) {
$user = new User();
$begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
// XXX: estimates 1d == 24h, which screws up days
// with leap seconds (1d == 24h + 1s). Thankfully they're
// few and far between.
$theend = strtotime($begindt) + 24 * 60 * 60;
$enddt = common_sql_date($theend);
$user->selectAdd();
$user->selectAdd('nickname');
$user->whereAdd("created >= '{$begindt}'");
$user->whereAdd("created < '{$enddt}'");
$user->orderBy('created');
$offset = ($i - 1) * SitemapPlugin::USERS_PER_MAP;
$limit = SitemapPlugin::USERS_PER_MAP;
$user->limit($offset, $limit);
$user->find();
while ($user->fetch()) {
$u[] = $user->nickname;
}
$c = Cache::instance();
if (!empty($c)) {
$c->set(Cache::key("sitemap:user:{$y}:{$m}:{$d}:{$i}"), $u, Cache::COMPRESSED, time() > $theend ? time() + 90 * 24 * 60 * 60 : time() + 5 * 60);
}
}
return $u;
}
示例10: getFacebookUser
function getFacebookUser($id)
{
$key = Cache::key(sprintf("FacebookBridgePlugin:userdata:%s", $id));
$c = Cache::instance();
if ($c) {
$obj = $c->get($key);
if ($obj) {
return $obj;
}
}
$url = sprintf("https://graph.facebook.com/%s", $id);
$client = new HTTPClient();
$resp = $client->get($url);
if (!$resp->isOK()) {
return null;
}
$user = json_decode($resp->getBody());
if ($user->error) {
return null;
}
if ($c) {
$c->set($key, $user);
}
return $user;
}
示例11: codeKey
/**
* Create a cache key for data dependent on code
*
* For cache elements that are dependent on changes in code, this creates
* a more-or-less fingerprint of the current running code and adds it to
* the cache key. In the case of an upgrade of core, or addition or
* removal of plugins, a new unique fingerprint is generated and used.
*
* There can still be problems with a) differences in versions of the
* plugins and b) people running code between official versions. This is
* usually a problem only for experienced users like developers, who know
* how to clear their cache.
*
* For sites that run code between versions (like the status.net cloud),
* there's an additional build number configuration setting.
*
* @param string $extra the real part of the key
*
* @return string full key
*/
static function codeKey($extra)
{
static $prefix = null;
if (empty($prefix)) {
$plugins = StatusNet::getActivePlugins();
$names = array();
foreach ($plugins as $plugin) {
$names[] = $plugin[0];
}
$names = array_unique($names);
asort($names);
// Unique enough.
$uniq = crc32(implode(',', $names));
$build = common_config('site', 'build');
$prefix = STATUSNET_VERSION . ':' . $build . ':' . $uniq;
}
return Cache::key($prefix . ':' . $extra);
}
示例12: intval
include_once "{$lib}/class/file.php";
include_once "{$lib}/share/link.php";
include_once "{$lib}/share/stdio.php";
include_once "{$lib}/share/string.php";
pieLoadLocale();
pieHead();
$_REQUEST['limit'] = intval(@$_REQUEST['limit']);
if ($_REQUEST['limit'] < 1) {
$_REQUEST['limit'] = 10;
}
if ($_REQUEST['limit'] > 100) {
$_REQUEST['limit'] = 100;
}
$page = new Page();
$cache = new Cache();
$cid = $cache->key('latest', array());
if ($GLOBALS['pie']['query_caching'] && $cache->exists($cid)) {
// Use existing cache.
$dump = trim(file_get_contents($cache->file($cid)));
$cache->update($cid);
$dump = explode("\n", $dump);
$data = array();
foreach ($dump as $i) {
$data[] = $i;
}
} else {
// Determine latest page changes.
$data = array();
for ($name = $page->first(); $name; $name = $page->next()) {
$data[] = $page->stamp . "\t{$name}";
}
示例13: 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) {
// TRANS: Exception thrown in the LDAP Common plugin when LDAP server is not available.
// TRANS: %s is the error message.
throw new LdapInvalidCredentialsException(sprintf(_m('Could not connect to LDAP server: %s'), $err->getMessage()));
}
// TRANS: Exception thrown in the LDAP Common plugin when LDAP server is not available.
// TRANS: %s is the error message.
throw new Exception(sprintf(_m('Could not connect to LDAP server: %s.'), $err->getMessage()));
}
$c = Cache::instance();
if (!empty($c)) {
$cacheObj = new MemcacheSchemaCache(array('c' => $c, 'cacheKey' => Cache::key('ldap_schema:' . $config_id)));
$ldap->registerSchemaCache($cacheObj);
}
self::$ldap_connections[$config_id] = $ldap;
}
return $ldap;
}
示例14: pieError
// A file with the name already exists.
if (!$file->read($name, 0)) {
pieError("FileReadError");
}
if ($file->meta['author'] == $GLOBALS['pie']['user'] && !@$_REQUEST['append']) {
// The upload is an update by the same user.
// Delete the previous version before saving the new one.
if (!$file->replace($name)) {
pieError("FileWriteError");
}
}
}
// Check for cached thumbnail images of former versions.
if ($GLOBALS['pie']['image_caching']) {
$cache = new Cache();
$cid = $cache->key('image', array('file' => $name));
if ($cache->exists($cid)) {
$cache->delete($cid);
}
} else {
$thumbnail = $GLOBALS['pie']['run_path'] . "/temp/_thumbnail_" . pieEncodeName($name);
if (file_exists($thumbnail)) {
unlink($thumbnail);
}
}
// Prepare meta data of the file:
$file->name = $name;
$file->meta = array('stamp' => time(), 'author' => $GLOBALS['pie']['user']);
// .. file size
if ($_FILES['upload']['size']) {
$file->meta['size'] = $_FILES['upload']['size'];
示例15: pieError
// We are trying to affect an other author's work
// ... which is only suitable for admins.
if (!pieIsSuperuser($GLOBALS['pie']['user'])) {
pieError("AuthorDiffers", array('action' => "{$context}history"));
}
}
// Ask user for acknowledgement to delete the page.
pieError("AskApproval");
}
// Delete the resource:
if (!$object->delete($target)) {
pieError("DeleteError");
}
if ($context == "page") {
// Do what is to be done with pages.
if ($object->meta['type'] != "alias") {
// Delete the cache, if available.
$cache = new Cache();
$cid = $cache->key('page', array('page' => $target));
if ($cache->exists($cid)) {
$cache->delete($cid);
}
if ($cache->exists($cache->key('latest', array()))) {
$cache->delete($cache->key('latest', array()));
}
}
$object->unlock($GLOBALS['pie']['user']);
}
pieLog("alter");
pieNotice("DeleteSuccessful");
pieTail();