• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Cache类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: getStaticStrings

 /**
  * Loads all the static strings from either the cache or the ini files. Note that ini files in modules are not verified for outdatedness, so if they were updated, just clear all the caches or hard reload a page
  * This method should not be called directly from outsite TranslationPeer except for testing and debugging purposes
  */
 public static function getStaticStrings($sLanguageId)
 {
     if (!isset(self::$STATIC_STRINGS[$sLanguageId])) {
         $oCache = new Cache($sLanguageId, DIRNAME_LANG);
         $aLanguageFiles = ResourceFinder::create()->addPath(DIRNAME_LANG, "{$sLanguageId}.ini")->all()->baseFirst()->find();
         if ($oCache->entryExists() && !$oCache->isOutdated($aLanguageFiles)) {
             self::$STATIC_STRINGS[$sLanguageId] = $oCache->getContentsAsVariable();
         } else {
             self::$STATIC_STRINGS[$sLanguageId] = array();
             //Get default strings
             foreach ($aLanguageFiles as $sLanguageFile) {
                 self::$STATIC_STRINGS[$sLanguageId] = array_merge(self::$STATIC_STRINGS[$sLanguageId], parse_ini_file($sLanguageFile));
             }
             //Get strings for modules
             foreach (ResourceFinder::create()->addExpression(DIRNAME_MODULES, ResourceFinder::ANY_NAME_OR_TYPE_PATTERN, ResourceFinder::ANY_NAME_OR_TYPE_PATTERN, DIRNAME_LANG, "{$sLanguageId}.ini")->all()->baseFirst()->find() as $sLanguageFile) {
                 self::$STATIC_STRINGS[$sLanguageId] = array_merge(self::$STATIC_STRINGS[$sLanguageId], parse_ini_file($sLanguageFile));
             }
             //Fix string encoding
             foreach (self::$STATIC_STRINGS[$sLanguageId] as $sStringKey => $sValue) {
                 self::$STATIC_STRINGS[$sLanguageId][$sStringKey] = StringUtil::encodeForDbFromFile($sValue);
             }
             $oCache->setContents(self::$STATIC_STRINGS[$sLanguageId]);
         }
     }
     return self::$STATIC_STRINGS[$sLanguageId];
 }
开发者ID:rapila,项目名称:cms-base,代码行数:30,代码来源:TranslationPeer.php


示例17: validate

 public function validate(Validation $array, $save = FALSE)
 {
     // uses PHP trim() to remove whitespace from beginning and end of all fields before validation
     $array->pre_filter('trim');
     // merge unvalidated fields, in case the subclass has set any.
     if (!isset($this->unvalidatedFields)) {
         $this->unvalidatedFields = array();
     }
     $this->unvalidatedFields = array_merge($this->unvalidatedFields, array('validation_rules', 'public', 'multi_value', 'deleted'));
     $array->add_rules('caption', 'required');
     $array->add_rules('data_type', 'required');
     if (array_key_exists('data_type', $array->as_array()) && $array['data_type'] == 'L') {
         if (empty($array['termlist_id'])) {
             $array->add_rules('termlist_id', 'required');
         } else {
             array_push($this->unvalidatedFields, 'termlist_id');
         }
     }
     $array->add_rules('system_function', 'length[1,30]');
     $parent_valid = parent::validate($array, $save);
     // clean up cached required fields in case validation rules have changed
     $cache = Cache::instance();
     $cache->delete_tag('required-fields');
     if ($save && $parent_valid) {
         // clear the cache used for attribute datatype and validation rules since the attribute has changed
         $cache = new Cache();
         // Type is the object name with _attribute stripped from the end
         $type = substr($this->object_name, 0, strlen($this->object_name) - 10);
         $cache->delete('attrInfo_' . $type . '_' . $this->id);
     }
     return $save && $parent_valid;
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:32,代码来源:ATTR_ORM.php


示例18: addEntry

 public static function addEntry($bID, $commentText, $name, $email, $approved, $cID, $uID = 0, $timestamp = null)
 {
     $txt = Loader::helper('text');
     $db = Loader::db();
     $query = "INSERT INTO btGuestBookEntries (bID, cID, uID, user_name, user_email, commentText, approved, entryDate) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
     $v = array($bID, $cID, intval($uID), $txt->sanitize($name), $txt->sanitize($email), $txt->sanitize($commentText), $approved, $timestamp);
     $res = $db->query($query, $v);
     $number = 1;
     //stupid cache stuff
     $ca = new Cache();
     $db = Loader::db();
     $count = $ca->get('GuestBookCount', $cID . "-" . $bID);
     if ($count && $number) {
         $count += $number;
     } else {
         $q = 'SELECT count(bID) as count
 FROM btGuestBookEntries
 WHERE bID = ?
 AND cID = ?
 AND approved=1';
         $v = array($bID, $cID);
         $rs = $db->query($q, $v);
         $row = $rs->FetchRow();
         $count = $row['count'];
     }
     $ca->set('GuestBookCount', $cID . "-" . $bID, $count);
 }
开发者ID:herent,项目名称:wordpress_site_importer,代码行数:27,代码来源:comment_lite.php


示例19: encodedKey

 public function encodedKey(Cache $oCache)
 {
     $sKey = $oCache->getKey();
     if ($this->key_encode) {
         $sKey = call_user_func($this->key_encode, $sKey);
     }
     return $sKey;
 }
开发者ID:rapila,项目名称:cms-base,代码行数:8,代码来源:CachingStrategy.php


示例20: after

 public function after()
 {
     parent::after();
     if ($this->cache === TRUE && $this->request->status === 200 && $this->session->user->manage_dash_mods === null) {
         $cache = new Cache($this->cache_config);
         $cache->set($this->request->uri . ' :: ' . $this->session->group, $this->request->response, $this->cache_tag, $this->cache_lifetime);
     }
 }
开发者ID:pedrosland,项目名称:kohana-cache,代码行数:8,代码来源:controller.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP CacheControl类代码示例发布时间:2022-05-20
下一篇:
PHP Cabinet类代码示例发布时间:2022-05-20
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap