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


PHP Cache::set方法代码示例

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


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

示例1: afterLayout

 function afterLayout()
 {
     if (Configure::read('Cache.disable') || Configure::read('ViewMemcache.disable')) {
         return true;
     }
     try {
         if (!empty($this->_View->viewVars['enableViewMemcache'])) {
             if (isset($this->_View->viewVars['viewMemcacheDuration'])) {
                 // CakeLog::write('debug', "ViewMemCache: duration override: {$this->_View->viewVars['viewMemcacheDuration']}");
                 @Cache::set(array('duration' => $this->_View->viewVars['viewMemcacheDuration'], null, 'view_memcache'));
                 //'+30 days' or seconds
             }
             if (!isset($this->_View->viewVars['viewMemcacheNoFooter'])) {
                 //CakeLog::write('debug', "ViewMemCache: footer disabled");
                 $this->cacheFooter = "\n<!-- ViewCached";
                 if ($this->gzipContent) {
                     $this->cacheFooter .= ' gzipped';
                 }
                 $this->cacheFooter .= ' ' . date('r') . ' -->';
             }
             if ($this->gzipContent && empty($this->_View->viewVars['viewMemcacheDisableGzip'])) {
                 //CakeLog::write('debug', "ViewMemCache: gzipping ".$this->request->here."\n\n".var_export($this->request,true)."\n\n".var_export($_SERVER,true));
                 @Cache::write($this->request->here, gzencode($this->_View->output . $this->cacheFooter, $this->compressLevel), 'view_memcache');
             } else {
                 //CakeLog::write('debug', "ViewMemCache: NOT gzipping ");
                 @Cache::write($this->request->here, $this->_View->output . $this->cacheFooter, 'view_memcache');
             }
         }
     } catch (Exception $e) {
         //do nothing
     }
     return true;
 }
开发者ID:Jpsstack,项目名称:cakephp-viewmemcache,代码行数:33,代码来源:ViewMemcacheHelper.php

示例2: invalidateUserResources

 /**
  * Invalidate all cached resources where the specified user ids were used as either the
  * owner or viewer id when a signed or OAuth request was made for the content by the application
  * identified in the security token.
  * @param opensocialIds Set of user ids to invalidate authenticated/signed content for
  * @param token identifying the calling application
  */
 function invalidateUserResources(array $opensocialIds, SecurityToken $token)
 {
     foreach ($opensocialIds as $opensocialId) {
         ++self::$marker;
         self::$makerCache->set('marker', self::$marker);
         $this->invalidationEntry->set($this->getKey($opensocialId, $token), self::$marker);
     }
 }
开发者ID:niryuu,项目名称:opOpenSocialPlugin,代码行数:15,代码来源:DefaultInvalidateService.php

示例3: project

 /**
  * Take a project key and return the properties
  *
  * @param string $identifier
  * @return array
  */
 public function project($identifier)
 {
     if (!$this->cache->has($identifier)) {
         $html = $this->fetch($identifier);
         $project = $this->parse($html);
         $this->cache->set($identifier, $project, $this->expiry);
     }
     return $this->cache->get($identifier);
 }
开发者ID:DerpMarceline,项目名称:widget,代码行数:15,代码来源:Curse.php

示例4: get

 public function get($groupName, $identifier, $function = null, $arguments = array())
 {
     $ret = $this->cache->get($groupName, $identifier, $this->lifetime);
     if ($ret == false && $function != null) {
         $ret = call_user_func_array($function, $arguments);
         $this->cache->set($groupName, $identifier, $ret);
     }
     return $ret;
 }
开发者ID:rotoballer,项目名称:emily,代码行数:9,代码来源:gantrycache.class.php

示例5: getTicket

 /**
  * 获取jsticket
  *
  * @return string
  */
 public function getTicket()
 {
     $key = 'overtrue.wechat.jsapi_ticket' . $this->appId;
     return $this->cache->get($key, function ($key) {
         $http = new Http(new AccessToken($this->appId, $this->appSecret));
         $result = $http->get(self::API_TICKET);
         $this->cache->set($key, $result['ticket'], $result['expires_in']);
         return $result['ticket'];
     });
 }
开发者ID:emilymwang8,项目名称:ajk-broker,代码行数:15,代码来源:Js.php

示例6: Cache

 function test_flush()
 {
     $c = new Cache();
     $c->set('foo', 'test', 0, 10);
     $c->set('bar', 'test2');
     $this->assertTrue($c->flush());
     // check that it also flushed dot-files for timeouts too
     $files = glob($c->dir . '/{,.}*', GLOB_BRACE);
     $this->assertEquals(count($files), 2);
 }
开发者ID:Selwyn-b,项目名称:elefant,代码行数:10,代码来源:CacheTest.php

示例7: lists

 /**
  * 获取颜色列表
  *
  * @return array
  */
 public function lists()
 {
     $key = 'overtrue.wechat.colors';
     return $this->cache->get($key, function ($key) {
         $result = $this->http->get(self::API_LIST);
         $this->cache->set($key, $result['colors'], 86400);
         // 1 day
         return $result['colors'];
     });
 }
开发者ID:emilymwang8,项目名称:ajk-broker,代码行数:15,代码来源:Color.php

示例8: write

 /**
  * Save values for a set of keys to cache
  *
  * @param array $keys list of values to save
  * @param int $expire expiration time
  * @return boolean true on success, false on failure
  */
 protected function write(array $keys, $expire = null)
 {
     #echo "writing template to cache";
     #printArray($keys);
     foreach ($keys as $k => $v) {
         $k = sha1($k);
         $rs = $this->Cache->set($k, $v, 0, $expire);
     }
     #$this->Cache->setMulti($keys, $expire);
     return true;
 }
开发者ID:railpage,项目名称:railpagecore,代码行数:18,代码来源:Template_Cache_Memcached.php

示例9: getToken

 /**
  * 获取Token
  *
  * @param bool $forceRefresh
  *
  * @return string
  */
 public function getToken($forceRefresh = false)
 {
     $cacheKey = $this->cacheKey;
     $cached = $this->cache->get($cacheKey);
     if ($forceRefresh || !$cached) {
         $token = $this->getTokenFromServer();
         $this->cache->set($cacheKey, $token['access_token'], $token['expires_in'] - 800);
         return $token['access_token'];
     }
     return $cached;
 }
开发者ID:stoneworld,项目名称:wechat,代码行数:18,代码来源:AccessToken.php

示例10: Cache

 function act_set()
 {
     $value = $_GET['value'];
     $cache = new Cache("group11");
     $cache->set("key1", $value, "60");
     return array();
 }
开发者ID:ohjack,项目名称:newErp,代码行数:7,代码来源:memcache.action.php

示例11: beforeFilter

 public function beforeFilter()
 {
     $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'admin' => false);
     $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'index', 'admin' => true);
     $this->Auth->logoutRedirect = array('controller' => 'contents', 'action' => 'homepage', 'admin' => false, 'vendor' => false);
     $this->Auth->authorize = array('Controller');
     $this->Auth->authenticate = array(AuthComponent::ALL => array('userModel' => 'User', 'fields' => array('username' => 'username', 'password' => 'password'), 'scope' => array('User.active' => 1)), 'Form');
     if (isset($this->request->params['admin']) && $this->request->params['prefix'] == 'admin') {
         $this->set('authUser', $this->Auth->user());
         $this->layout = 'admin';
     } elseif (isset($this->request->params['vendor']) && $this->request->params['prefix'] == 'vendor') {
         $this->set('authUser', $this->Auth->user());
         $this->layout = 'vendor';
     } else {
         $this->Auth->allow();
         $menucategories = Cache::read('menucategories');
         if (!$menucategories) {
             $menucategories = ClassRegistry::init('Product')->find('all', array('recursive' => -1, 'contain' => array('User', 'Category'), 'fields' => array('Category.id', 'Category.name', 'Category.slug'), 'conditions' => array('User.active' => 1, 'Product.active' => 1, 'Product.category_id >' => 0, 'Category.id >' => 0), 'order' => array('Category.name' => 'ASC'), 'group' => array('Category.id')));
             Cache::set(array('duration' => '+10 minutes'));
             Cache::write('menucategories', $menucategories);
         }
         $this->set(compact('menucategories'));
         $menuvendors = Cache::read('menuvendors');
         if (!$menuvendors) {
             $menuvendors = ClassRegistry::init('User')->getVendors();
             Cache::set(array('duration' => '+10 minutes'));
             Cache::write('menuvendors', $menuvendors);
         }
         $this->set(compact('menuvendors'));
     }
     if ($this->RequestHandler->isAjax()) {
         $this->layout = 'ajax';
     }
     $this->AutoLogin->settings = array('model' => 'Member', 'username' => 'name', 'password' => 'pass', 'plugin' => '', 'controller' => 'members', 'loginAction' => 'signin', 'logoutAction' => 'signout', 'cookieName' => 'rememberMe', 'expires' => '+1 month', 'active' => true, 'redirect' => true, 'requirePrompt' => true);
 }
开发者ID:beyondkeysystem,项目名称:testone,代码行数:35,代码来源:AppController.php

示例12: get

 public function get($id = 0, $useCache = true)
 {
     if (!$id) {
         $id =& $this->id;
     }
     if ($useCache && ($cache = Cache::get($id))) {
         return $cache;
     }
     parent::get($id, !USE_CACHE);
     $this->photos = array();
     $i = 0;
     if (!is_array($this->files['photo'])) {
         return $this;
     }
     foreach ($this->files['photo'] as &$f) {
         $f->main =& Image::createThumbnail($f->name, $this->folder->config['imgWidth']);
         $f->thumb =& Image::createThumbnail($f->name, $this->folder->config['imgThumbWidth']);
         if (++$i == 1) {
             $f->fpthumb =& Image::createThumbnail($f->name, $this->folder->config['fpThumbWidth']);
         }
         $this->photos[] = $f;
     }
     if ($this->pub_on > 0) {
         Cache::set($id, $this);
     }
     return $this;
 }
开发者ID:rezaprima,项目名称:icms,代码行数:27,代码来源:photo.php

示例13: action_add_template_vars

 function action_add_template_vars($theme)
 {
     $username = Options::get('freshsurf__username');
     $password = Options::get('freshsurf__password');
     $count = Options::get('freshsurf__count');
     if ($username != '' && $password != '') {
         if (Cache::has('freshsurf__' . $username)) {
             $response = Cache::get('freshsurf__' . $username);
         } else {
             $request = new RemoteRequest("https://{$username}:{$password}@" . self::BASE_URL . "posts/recent?count={$count}", 'GET', 20);
             $request->execute();
             $response = $request->get_response_body();
             Cache::set('freshsurf__' . $username, $response);
         }
         $delicious = @simplexml_load_string($response);
         if ($delicious instanceof SimpleXMLElement) {
             $theme->delicious = $delicious;
         } else {
             $theme->delicious = @simplexml_load_string('<posts><post href="#" description="Could not load feed from delicious.  Is username/password correct?"/></posts>');
             Cache::expire('freshsurf__' . $username);
         }
     } else {
         $theme->delicious = @simplexml_load_string('<posts></posts>');
     }
 }
开发者ID:habari-extras,项目名称:FreshSurf,代码行数:25,代码来源:FreshSurf.plugin.php

示例14: getCountries

 public function getCountries($data = array())
 {
     $cache = 'countries.' . json_encode($data);
     $return = Cache::find($cache);
     if (is_array($return)) {
         return $return;
     }
     $sql = "SELECT * FROM PREFIX_country";
     $sort_data = array('name', 'iso_code_2', 'iso_code_3');
     if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
         $sql .= " ORDER BY " . $data['sort'];
     } else {
         $sql .= " ORDER BY name";
     }
     if (isset($data['order']) && $data['order'] == 'DESC') {
         $sql .= " DESC";
     } else {
         $sql .= " ASC";
     }
     if (isset($data['start']) || isset($data['limit'])) {
         if ($data['start'] < 0) {
             $data['start'] = 0;
         }
         if ($data['limit'] < 1) {
             $data['limit'] = 20;
         }
         $sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit'];
     }
     $return = $this->fetchAll($sql);
     Cache::set($cache, $return);
     return $return;
 }
开发者ID:wardvanderput,项目名称:SumoStore,代码行数:32,代码来源:country.php

示例15: getWeather

function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cachetime = 0)
{
    $url = "http://api.openweathermap.org/data/2.5/weather?q=" . $loc . "&appid=" . $appid . "&lang=" . $lang . "&units=" . $units . "&mode=xml";
    $cached = Cache::get('curweather' . md5($url));
    $now = new DateTime();
    if (!is_null($cached)) {
        $cdate = get_pconfig(local_user(), 'curweather', 'last');
        $cached = unserialize($cached);
        if ($cdate + $cachetime > $now->getTimestamp()) {
            return $cached;
        }
    }
    try {
        $res = new SimpleXMLElement(fetch_url($url));
    } catch (Exception $e) {
        info(t('Error fetching weather data.\\nError was: ' . $e->getMessage()));
        return false;
    }
    if ((string) $res->temperature['unit'] === 'metric') {
        $tunit = '°C';
        $wunit = 'm/s';
    } else {
        $tunit = '°F';
        $wunit = 'mph';
    }
    if (trim((string) $res->weather['value']) == trim((string) $res->clouds['name'])) {
        $desc = (string) $res->clouds['name'];
    } else {
        $desc = (string) $res->weather['value'] . ', ' . (string) $res->clouds['name'];
    }
    $r = array('city' => (string) $res->city['name'][0], 'country' => (string) $res->city->country[0], 'lat' => (string) $res->city->coord['lat'], 'lon' => (string) $res->city->coord['lon'], 'temperature' => (string) $res->temperature['value'][0] . $tunit, 'pressure' => (string) $res->pressure['value'] . (string) $res->pressure['unit'], 'humidity' => (string) $res->humidity['value'] . (string) $res->humidity['unit'], 'descripion' => $desc, 'wind' => (string) $res->wind->speed['name'] . ' (' . (string) $res->wind->speed['value'] . $wunit . ')', 'update' => (string) $res->lastupdate['value'], 'icon' => (string) $res->weather['icon']);
    set_pconfig(local_user(), 'curweather', 'last', $now->getTimestamp());
    Cache::set('curweather' . md5($url), serialize($r), CACHE_HOUR);
    return $r;
}
开发者ID:ZerGabriel,项目名称:friendica-addons,代码行数:35,代码来源:curweather.php


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