本文整理汇总了PHP中Cache::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::fetch方法的具体用法?PHP Cache::fetch怎么用?PHP Cache::fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::fetch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadCachedCategories
public function loadCachedCategories()
{
if ($this->cache) {
$result = $this->cache->fetch($this->cacheKey);
if (isset($result['categories']) && isset($result['parentChildIds'])) {
$this->categories = $result['categories'];
foreach ($this->categories as $cat) {
$cat->setCategoryManager($this);
}
$this->parentChildIds = $result['parentChildIds'];
}
}
}
示例2: cacheTree
public static function cacheTree($path, $force = false)
{
// split path into array
if (is_string($path)) {
$path = Site::splitPath($path);
}
// check if this tree has already been cached
$cacheKey = 'cacheTree:' . implode('/', $path);
if (!Site::$autoPull || !$force && Cache::fetch($cacheKey)) {
return 0;
}
Cache::store($cacheKey, true);
// get tree map from parent
$remoteTree = Emergence::resolveCollectionFromParent($path);
if (!$remoteTree) {
return 0;
}
$filesResolved = 0;
$startTime = time();
foreach ($remoteTree['files'] as $remotePath => $remoteFile) {
$node = Site::resolvePath($remotePath);
if ($node && $node->Timestamp >= $startTime) {
$filesResolved++;
}
}
return $filesResolved;
}
示例3: _verifySign
private function _verifySign($domain, $text, $sign)
{
include_once KFL_DIR . '/Libs/Cache.class.php';
$filename = $domain . ".txt";
$cache = new Cache(86400 * 300, 0);
$cache->setCacheStore("file");
// or memcache
$cache->setCacheDir(APP_TEMP_DIR);
$cache->setCacheFile($filename);
if ($cache->isCached()) {
$client = unserialize($cache->fetch());
} else {
require_once 'ClientModel.class.php';
$ClientModel = new ClientModel();
$client = $ClientModel->getClientByName($domain);
if ($client) {
$cache->save(serialize($client));
} else {
return false;
}
}
$this->_private_key = $client['private_key'];
if (hmac($this->_private_key, $text, 'sha1') == $sign) {
return true;
} else {
return false;
}
}
示例4: fetchCache
public function fetchCache()
{
$this->pocDispatcher->dispatch(PocEventNames::FUNCTION_FETCHCACHE_BEGINNING, new BaseEvent($this));
$this->output = $this->cache->fetch($this->hasher->getKey());
if ($this->output) {
$this->pocDispatcher->dispatch(PocEventNames::GET_OUTPUT_FROM_CACHE, new BaseEvent($this));
}
}
示例5: __construct
public function __construct($filter, $start, $count)
{
$cache = new Cache('note_list', false);
if (!($metaList = $cache->fetch(compact('filter', 'start', 'count')))) {
$metaList = Evernote::_noteStore()->findNotesMetadata(AUTH_TOKEN, $filter, $start, $count, new EDAM\NoteStore\NotesMetadataResultSpec());
$cache->store($metaList);
}
$this->_metaList = $metaList;
$this->total = $metaList->totalNotes;
}
示例6: load
public function load($token)
{
if (!empty($token)) {
$cache = new Cache('user');
if (!($user = $cache->fetch($token))) {
$user = self::_userStore()->getUser($token);
$cache->store($user);
}
$this->user = $user;
}
return $this;
}
示例7: getByHandle
public static function getByHandle($collectionID, $handle)
{
$cacheKey = static::getCacheKey($collectionID, $handle);
if (false === ($record = Cache::fetch($cacheKey))) {
$record = DB::oneRecord('SELECT * FROM `%s` WHERE CollectionID = %u AND Handle = "%s" ORDER BY ID DESC LIMIT 1', array(static::$tableName, $collectionID, DB::escape($handle)));
// don't cache the temporary "Phantom" records created as placeholders during write
if ($record['Status'] != 'Phantom') {
Cache::store($cacheKey, $record);
}
}
return $record ? new static($record['Handle'], $record) : null;
}
示例8: load
public function load($guid)
{
if (!empty($guid)) {
$cache = new Cache('notebook');
if (!($notebook = $cache->fetch($guid))) {
$notebook = self::_noteStore()->getNotebook(AUTH_TOKEN, $guid);
$cache->store($notebook);
}
$this->notebook = $notebook;
}
return $this;
}
示例9: loadResource
/**
* Loads a HTTP resource.
*
* @param string $url
* @param array $parameters
*
* @return array
*/
public function loadResource($url, $parameters)
{
$signature = $this->createSignature($url, $parameters);
if ($this->cache->contains($signature)) {
return $this->cache->fetch($signature);
}
$parameters['format'] = 'json';
$parameters['api_key'] = $this->config->getApiKey();
$url = $this->config->getApiEndpoint() . $this->buildQueryUrl($url, $parameters);
$response = $this->guzzle->request('GET', $url);
$body = $this->processResponse($response);
$this->cache->save($signature, $body['results']);
return $body['results'];
}
示例10: Dwoo_Plugin_rss
function Dwoo_Plugin_rss(Dwoo_Core $dwoo, $feed, $assign = 'rss_items', $limit = 5, $cacheTime = 60)
{
$cacheKey = 'rss:' . $feed;
if (false === ($rss = Cache::fetch($cacheKey))) {
$rss = new RssReader();
$rss->load($feed);
Cache::store($cacheKey, $rss, $cacheTime);
}
if ($limit) {
$dwoo->assignInScope(array_slice($rss->getItems(), 0, $limit), $assign);
} else {
$dwoo->assignInScope($rss->getItems(), $assign);
}
return '';
}
示例11: getSourceCode
public static function getSourceCode($minifier, $cacheHashOrSourceReport, $skipCache = false)
{
$cacheHash = is_string($cacheHashOrSourceReport) ? $cacheHashOrSourceReport : $cacheHashOrSourceReport['hash'];
$cacheKey = "{$minifier}:{$cacheHash}";
if (!$skipCache && ($code = Cache::fetch($cacheKey))) {
return $code;
}
if (is_array($cacheHashOrSourceReport) && is_array($cacheHashOrSourceReport['files'])) {
$code = '';
foreach ($cacheHashOrSourceReport['files'] as $path => $fileData) {
$code .= $minifier::minify(file_get_contents(SiteFile::getRealPathByID($fileData['ID'])));
}
Cache::store($cacheKey, $code);
return $code;
}
return null;
}
示例12: sqlCache
/**
Retrieve from cache; or save SQL query results to cache if not
previously executed
@param $_cmd string
@param $_bind mixed
@param $_id string
@param $_ttl integer
@private
**/
private static function sqlCache($_cmd, $_bind = NULL, $_id = 'DB', $_ttl = 0)
{
$_hash = 'sql.' . F3::hashCode($_cmd);
$_db =& F3::$global[$_id];
$_cached = Cache::cached($_hash);
if ($_cached && time() - $_cached['time'] < $_ttl) {
// Gather cached SQL queries for profiler
F3::$global['PROFILE'][$_id]['cache'][$_cmd]++;
// Retrieve from cache
$_db = Cache::fetch($_hash);
} else {
self::sqlExec($_cmd, NULL, $_id);
if (!F3::$global['ERROR']) {
// Save to cache
unset($_db['pdo'], $_db['query']);
Cache::store($_hash, $_db);
}
}
}
示例13: sqlCache
/**
Retrieve from cache; or save SQL query results to cache if not
previously executed
@param $_cmd string
@param $_bind mixed
@param $_id string
@param $_ttl integer
@private
**/
private static function sqlCache($_cmd, $_bind = NULL, $_id = 'DB', $_ttl = 0)
{
$_hash = 'sql.' . F3::hashCode($_cmd);
$_db =& F3::$global[$_id];
$_cached = Cache::cached($_hash);
if ($_cached && time() - $_cached['time'] < $_ttl) {
// Gather cached SQL queries for profiler
F3::$global['PROFILE'][$_id]['cache'][$_cmd]++;
// Retrieve from cache, unserialize, and restore DB variable
$_db = unserialize(gzinflate(Cache::fetch($_hash)));
} else {
self::sqlExec($_cmd, NULL, $_id);
if (!F3::$global['ERROR']) {
// Serialize, compress and cache
unset($_db['pdo'], $_db['query']);
Cache::store($_hash, gzdeflate(serialize($_db)));
}
}
}
示例14: getFeedData
public static function getFeedData($url, $cacheKey = false, $cacheTime = null)
{
if ($cacheTime === null) {
$cacheTime = static::$defaultCacheTime;
}
// get context
if (!isset(static::$_streamContext)) {
static::$_streamContext = stream_context_create(array('http' => array('timeout' => static::$requestTimeout)));
}
$failureKey = 'fail:' . $cacheKey;
if (!($twitterData = Cache::fetch($cacheKey)) && !Cache::fetch($failureKey)) {
$twitterData = @json_decode(@file_get_contents($url, false, static::$_streamContext), true);
if (empty($twitterData)) {
Cache::store($failureKey, true, static::$failureDelay);
}
Cache::store($cacheKey, $twitterData, $cacheTime);
}
return $twitterData ? $twitterData : false;
}
示例15: weather
function weather($code)
{
$code = str_replace('-', ' ', $code);
$code = urlencode($code);
$cache = new Cache();
$cache_name = 'weather_' . $code;
$xml = '';
$use_errors = libxml_use_internal_errors(true);
if (!($xml = simplexml_load_string($cache->fetch($cache_name)))) {
$result = @file_get_contents('http://api.openweathermap.org/data/2.5/forecast/daily?q=' . $code . ',uk&mode=xml&units=metric&cnt=7');
if (!$result) {
return false;
}
$cache->store($cache_name, $result, 86000);
$xml = simplexml_load_string($result);
}
libxml_clear_errors();
libxml_use_internal_errors($use_errors);
return $xml;
}