当前位置: 首页>>代码示例>>PHP>>正文


PHP Cache类代码示例

本文整理汇总了PHP中Cache的典型用法代码示例。如果您正苦于以下问题:PHP Cache类的具体用法?PHP Cache怎么用?PHP Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSetNoToString

 public function testSetNoToString()
 {
     $object = new CacheTestNoToSTring();
     $cache = new Cache();
     $this->setExpectedException('PHPUnit_Framework_Error');
     $cache->set($object, 'broken');
 }
开发者ID:aurmil,项目名称:dflydev-placeholder-resolver,代码行数:7,代码来源:CacheTest.php

示例2: parseDir

 public function parseDir($dir)
 {
     if (!$dir) {
         return;
     }
     $cache = new Cache($dir);
     $settings = [];
     if (false && $cache->isBuilt()) {
         $settings = $cache->get();
     } else {
         /**
          * @T00D00
          * We need to parse config directory recursively.
          * defaults.php and env.php needs to be taken differently (as root namespace).
          */
         $files = ["defaults" => $dir . 'config' . path('ds') . "defaults.php", "database" => $dir . 'config' . path('ds') . "database.php", "router" => $dir . 'config' . path('ds') . "router.php", "env" => $dir . 'config' . path('ds') . "env.php"];
         foreach ($files as $key => $file) {
             $content = is_file($file) ? require $file : [];
             if (in_array($key, ['defaults', 'env'])) {
                 $settings = $this->merge($settings, $content);
             } else {
                 $settings[$key] = $content;
             }
         }
     }
     $this->data = $this->merge($this->data, $settings);
 }
开发者ID:pckg,项目名称:framework,代码行数:27,代码来源:Config.php

示例3: act_getUserList

 public function act_getUserList()
 {
     $list_english_id = addslashes($_GET['englishId']);
     $list_english_id = trim($list_english_id);
     if ($list_english_id === '') {
         self::$errCode = '5506';
         self::$errMsg = 'Mail englishId is null,please input again!';
         return array();
     } else {
         $cacheName = md5("rss_name_list");
         $memc_obj = new Cache(C('CACHEGROUP'));
         $rssNameInfo = $memc_obj->get_extral($cacheName);
         if (!empty($rssNameInfo)) {
             return unserialize($rssNameInfo);
         } else {
             $getData = new MailApiModel();
             $getUserList = $getData->checkPower($list_english_id);
             $rssNameInfo = $this->checkReturnData($getUserList, array());
             $isok = $memc_obj->set_extral($cacheName, serialize($rssNameInfo), 14400);
             if (!$isok) {
                 self::$errCode = 0;
                 self::$errMsg = 'memcache缓存出错!';
             }
             self::$errCode = mailApiModel::$errCode;
             self::$errMsg = mailApiModel::$errMsg;
             return $rssNameInfo;
         }
     }
 }
开发者ID:ohjack,项目名称:newErp,代码行数:29,代码来源:mailApi.action.php

示例4: create_nonce

 /**
  * Method to create a nonce, either from a service call (when the caller type is a website) or from the Warehouse
  * (when the caller type is an Indicia user.
  */
 public static function create_nonce($type, $website_id)
 {
     $nonce = sha1(time() . ':' . rand() . $_SERVER['REMOTE_ADDR'] . ':' . kohana::config('indicia.private_key'));
     $cache = new Cache();
     $cache->set($nonce, $website_id, $type, Kohana::config('indicia.nonce_life'));
     return $nonce;
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:11,代码来源:MY_security.php

示例5: renderFile

 public function renderFile()
 {
     //Send Content-Type
     $sCharset = Settings::getSetting('encoding', 'browser', 'utf-8');
     if ($this->sType === ResourceIncluder::RESOURCE_TYPE_CSS) {
         header("Content-Type: text/css;charset={$sCharset}");
     } else {
         if ($this->sType === ResourceIncluder::RESOURCE_TYPE_JS) {
             header("Content-Type: text/javascript;charset={$sCharset}");
         }
     }
     //Find consolidated resources
     $aKeys = array();
     while (Manager::hasNextPathItem()) {
         $aKeys[] = Manager::usePath();
     }
     $sKey = 'consolidated-output-' . $this->sType . '-' . implode('|', $aKeys);
     $oCachingStrategy = clone CachingStrategy::fromConfig('file');
     $oCache = new Cache($sKey, 'resource', $oCachingStrategy);
     $oItemCachingStrategy = clone $oCachingStrategy;
     $oItemCachingStrategy->init(array('key_encode' => null));
     $oCache->sendCacheControlHeaders();
     if (!$oCache->entryExists(false)) {
         foreach ($aKeys as $sItemKey) {
             $oItemCache = new Cache($sItemKey, DIRNAME_PRELOAD, $oItemCachingStrategy);
             if (!$oItemCache->entryExists(false)) {
                 throw new Exception("Consolidated resource {$sItemKey} does not exist.");
             }
             $oCache->setContents($oItemCache->getContentsAsString() . "\n", false, true);
         }
     }
     $oCache->sendCacheControlHeaders();
     $oCache->passContents(true);
 }
开发者ID:rapila,项目名称:cms-base,代码行数:34,代码来源:ConsolidatedResourceFileModule.php

示例6: render

 /**
  * Renders template to output.
  * @return void
  */
 public function render()
 {
     if ($this->file == NULL) {
         // intentionally ==
         throw new InvalidStateException("Template file name was not specified.");
     }
     $cache = new Cache($storage = $this->getCacheStorage(), 'Nette.FileTemplate');
     if ($storage instanceof PhpFileStorage) {
         $storage->hint = str_replace(dirname(dirname($this->file)), '', $this->file);
     }
     $cached = $compiled = $cache->load($this->file);
     if ($compiled === NULL) {
         try {
             $compiled = "<?php\n\n// source file: {$this->file}\n\n?>" . $this->compile();
         } catch (TemplateException $e) {
             $e->setSourceFile($this->file);
             throw $e;
         }
         $cache->save($this->file, $compiled, array(Cache::FILES => $this->file, Cache::CONSTS => 'Framework::REVISION'));
         $cached = $cache->load($this->file);
     }
     if ($cached !== NULL && $storage instanceof PhpFileStorage) {
         LimitedScope::load($cached['file'], $this->getParameters());
     } else {
         LimitedScope::evaluate($compiled, $this->getParameters());
     }
 }
开发者ID:riskatlas,项目名称:micka,代码行数:31,代码来源:FileTemplate.php

示例7: cachedFrontend

 public function cachedFrontend($bIsPreview = false)
 {
     $oCacheKey = $this->cacheKey();
     $oCache = null;
     if ($oCacheKey !== null && !$bIsPreview) {
         $sPrefix = 'frontend_module_' . $this->getModuleName() . '_' . ($this->oLanguageObject ? $this->oLanguageObject->getPKString() : 'data_' . $this->oData);
         $oCache = new Cache($oCacheKey->render($sPrefix), DIRNAME_FULL_PAGE);
         $bIsCached = $oCache->entryExists();
         $bIsOutdated = false;
         if ($bIsCached) {
             if ($this->oLanguageObject) {
                 $bIsOutdated = $oCache->isOlderThan($this->oLanguageObject);
             }
             if (!$bIsOutdated) {
                 return $oCache->getContentsAsString();
             }
         }
     }
     $sResult = $this->renderFrontend();
     if ($sResult instanceof Template) {
         $sResult = $sResult->render();
     }
     if ($oCache) {
         $oCache->setContents($sResult);
     }
     return $sResult;
 }
开发者ID:rapila,项目名称:cms-base,代码行数:27,代码来源:FrontendModule.php

示例8: view

 /**
  * Returns the value of a view ane merges the config with any data passed to it
  *
  * @param   string        name of view
  * @param   boolean|array optional array of data to pass to the view
  * @param   string        file extension
  * @param   boolean|int   lifetime of cache. if set to true it will use the default
  *                            cache from the pages config or use an int if it is passed one
  * @return  string        contents of view or cache file
  */
 public static function view($view, $config = FALSE, $type = FALSE, $lifetime = FALSE)
 {
     $page = Pages::instance();
     // Setup caching and return the cache file it it works
     if ($lifetime) {
         $cache = new Cache();
         $cache_name = $page->getCacheIdForView($view . $type . serialize($data));
         if ($output = $cache->get($cache_name)) {
             return $output;
         }
     }
     // Load the view
     $view = new View($view, $config, $type);
     $output = $view->render();
     // Convert to markdown automatically
     if ($type == 'markdown' || $type == 'mdown' || $type == 'md') {
         $output = markdown::to_html($output);
     }
     // Store into cache
     if ($lifetime) {
         // Setup lifetime
         if ($lifetime === TRUE) {
             $lifetime = $page->cache_lifetime;
         } else {
             $lifetime = (int) $lifetime;
         }
         // Store the cache
         $cache->set($cache_name, $output, NULL, $lifetime);
     }
     return $output;
 }
开发者ID:uxturtle,项目名称:pages-module,代码行数:41,代码来源:page.php

示例9: setUrlToCache

 protected function setUrlToCache()
 {
     $url = $this->findUrlFromDB();
     $cache = new \Cache(['path' => __DIR__ . '/../runtime/redirectCache/', 'name' => 'default', 'extension' => '.cache']);
     $cache->store($this->currentUrl, $url);
     return $url;
 }
开发者ID:tolik505,项目名称:bl,代码行数:7,代码来源:Redirect.php

示例10: indexAction

 function indexAction()
 {
     /* @var $model CidadesModel */
     $model = newModel('CidadesModel');
     /* @var $v CidadeVO */
     $start = microtime(true);
     $estado = url_parans(0) ? url_parans(0) : inputPost('estado');
     $cidade = url_parans(1) ? url_parans(1) : inputPost('cidade');
     if ($estado > 0 or preg_match('/^[A-Z]{2}$/i', $estado)) {
         $cache = new Cache('cidades.' . $estado, 60);
         if (!($options = $cache->getContent())) {
             $cidades = $model->getCidades($estado);
             if (count($cidades)) {
                 $options = formOption('-- Selecione a cidade --', '');
             } else {
                 $options = formOption('-- Selecione o estado --', '');
             }
             foreach ($cidades as $v) {
                 $options .= formOption($v->getTitle(), $v->getId(), false);
             }
             # Salvando cache
             $cache->setContent($options);
         }
         echo preg_replace(['/(value="' . preg_quote($cidade) . '")/', '/>(' . preg_quote($cidade) . ')</'], ['$1 selected=""', 'selected="" >$1<'], $options);
     }
     $end = microtime(true);
     echo "\n\n<!-- " . number_format(($end - $start) * 1000, 5, ',', '.') . "ms --> Buscou por {$cidade}";
     exit;
 }
开发者ID:jhonlennon,项目名称:estrutura-mvc,代码行数:29,代码来源:indexController.class.php

示例11: render

 /**
  * Renders template to output.
  * @return void
  */
 public function render()
 {
     if ($this->file == NULL) {
         // intentionally ==
         throw new InvalidStateException("Template file name was not specified.");
     }
     $this->__set('template', $this);
     $shortName = str_replace(Environment::getVariable('appDir'), '', $this->file);
     $cache = new Cache($this->getCacheStorage(), 'Nette.Template');
     $key = trim(strtr($shortName, '\\/@', '.._'), '.') . '-' . md5($this->file);
     $cached = $content = $cache[$key];
     if ($content === NULL) {
         if (!$this->getFilters()) {
             $this->onPrepareFilters($this);
         }
         if (!$this->getFilters()) {
             LimitedScope::load($this->file, $this->getParams());
             return;
         }
         $content = $this->compile(file_get_contents($this->file), "file …{$shortName}");
         $cache->save($key, $content, array(Cache::FILES => $this->file, Cache::EXPIRE => self::$cacheExpire));
         $cache->release();
         $cached = $cache[$key];
     }
     if ($cached !== NULL && self::$cacheStorage instanceof TemplateCacheStorage) {
         LimitedScope::load($cached['file'], $this->getParams());
         fclose($cached['handle']);
     } else {
         LimitedScope::evaluate($content, $this->getParams());
     }
 }
开发者ID:regiss,项目名称:texyla-s-Nete1-PhP-5.2,代码行数:35,代码来源:Template.php

示例12: osc_latestTweets

function osc_latestTweets($num = 5)
{
    require_once osc_lib_path() . 'osclass/classes/Cache.php';
    $cache = new Cache('admin-twitter', 900);
    if ($cache->check()) {
        return $cache->retrieve();
    }
    $list = array();
    $content = osc_file_get_contents('https://twitter.com/statuses/user_timeline/osclass.rss');
    if ($content) {
        $xml = simplexml_load_string($content);
        if (isset($xml->error)) {
            return $list;
        }
        $count = 0;
        foreach ($xml->channel->item as $item) {
            $list[] = array('link' => strval($item->link), 'title' => strval($item->title), 'pubDate' => strval($item->pubDate));
            $count++;
            if ($count == $num) {
                break;
            }
        }
    }
    $cache->store($list);
    return $list;
}
开发者ID:semul,项目名称:Osclass,代码行数:26,代码来源:feeds.php

示例13: processCache

 public function processCache($params)
 {
     if ($this->getOption("cacheEnabled")) {
         // check the database for cache
         $c = new Cache($this);
         $cacheId = $this->getCacheId($params);
         // check whether cache is valid, and if so, retrieve content
         // from the cache. Content is loaded into the cache with
         // this call.
         if ($c->isValid($cacheId)) {
             // parse cache content back from string to suitable object with
             // deformatCacheContent method different for every request type
             $this->setResult(true, $this->deformatCacheContent($c->getContent()));
         } else {
             // execute request like it would if there was no cache
             $this->parseRequest($params);
             // format result into string for db storage
             $cacheContent = $this->formatCacheContent($this->result);
             // save formatted result to cache
             $c->save($cacheId, $cacheContent);
         }
     } else {
         // caching is not enabled, just parse the request
         $this->parseRequest($params);
     }
 }
开发者ID:svgorbunov,项目名称:ScrollsModRepo,代码行数:26,代码来源:Request.php

示例14: common

 public function common($params)
 {
     $Register = Register::getInstance();
     $output = '';
     if (!strpos($params, '{{ users_rating }}')) {
         return $params;
     }
     $Cache = new Cache();
     $Cache->lifeTime = 600;
     if ($Cache->check('pl_users_rating')) {
         $users = $Cache->read('pl_users_rating');
         $users = json_decode($users, true);
     } else {
         $users = $this->DB->select('users', DB_ALL, array('order' => '`rating` DESC', 'limit' => $this->limit));
         //$users = $this->DB->query($sql);
         $Cache->write(json_encode($users), 'pl_users_rating', array());
     }
     if (!empty($users)) {
         foreach ($users as $key => $user) {
             $link = get_link($user['name'], getProfileUrl($user['id']));
             $ava = file_exists(ROOT . '/sys/avatars/' . $user['id'] . '.jpg') ? get_url('/sys/avatars/' . $user['id'] . '.jpg') : get_url('/sys/img/noavatar.png');
             $output .= sprintf($this->wrap, $ava, $link, $user['rating'], $user['posts']);
         }
     }
     $output .= '<div class="etopu">' . get_link('Весь рейтинг', '/users/index?order=rating') . '</div>';
     return str_replace('{{ users_rating }}', $output, $params);
 }
开发者ID:VictorSproot,项目名称:AtomXCMS-2,代码行数:27,代码来源:index.php

示例15: actSendList

 public function actSendList()
 {
     $is_new = isset($_REQUEST["is_new"]) ? $_REQUEST["is_new"] : 0;
     if (!in_array($is_new, array(0, 1))) {
         self::$errCode = 10000;
         self::$errMsg = "更新参数非法!";
         return false;
     }
     $cacheName = md5("notice_name_list");
     $memc_obj = new Cache(C('CACHEGROUP'));
     $noticeNameInfo = $memc_obj->get_extral($cacheName);
     if (!empty($noticeNameInfo) && empty($is_new)) {
         return unserialize($noticeNameInfo);
     } else {
         $noticeNameInfo = NoticeApiModel::showNameList();
         self::$errCode = NoticeApiModel::$errCode;
         self::$errMsg = NoticeApiModel::$errMsg;
         $isok = $memc_obj->set_extral($cacheName, serialize($noticeNameInfo), 14400);
         if (!$isok) {
             self::$errCode = 0;
             self::$errMsg = 'memcache缓存出错!';
             //return false;
         }
         return $noticeNameInfo;
     }
 }
开发者ID:ohjack,项目名称:newErp,代码行数:26,代码来源:noticeApiCurd.action.php


注:本文中的Cache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。