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


PHP Cache::getInstance方法代码示例

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


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

示例1: find_file

 /**
  * Searches for a file at the filesystem of the game
  *
  * @param   string  $s_directory  directory name
  * @param   string  $s_file       filename with subdirectory
  * @param   string  $s_extension  extension to search for
  * @return  string|bool         Returns FALSE if the file is not found, otherwise the path
  *
  * @copyright   The original copyright hold the developers of the Kohana PHP frameworks.
  *              This method is a modified one.
  */
 public static function find_file($s_directory, $s_file, $s_extension = NULL)
 {
     if (Cache::getInstance()->exists('file_' . $s_file)) {
         return Cache::getInstance()->get('file_' . $s_file);
     }
     if (is_null($s_extension)) {
         $s_extension = EXT;
     } else {
         $s_extension ? $s_extension = ".{$s_extension}" : ($s_extension = '');
     }
     // Create a partial path of the filename
     $path = $s_directory . DIRECTORY_SEPARATOR . $s_file . $s_extension;
     // The file has not been found yet
     $m_found = FALSE;
     foreach (self::$a_paths as $directory) {
         if (is_file($directory . $path)) {
             // A path has been found, so set it and stop searching
             $m_found = $directory . $path;
             // if file was found and isn't cached, then cached it for one-day
             if (!Cache::getInstance()->exists('file_' . $s_file)) {
                 Cache::getInstance()->set("file_" . $s_file, $m_found, 86400);
             }
             break;
         }
     }
     return $m_found;
 }
开发者ID:nedron92,项目名称:logd-oop,代码行数:38,代码来源:core.php

示例2: getGeoInfo

 public function getGeoInfo($ip)
 {
     $cache = Cache::getInstance();
     $return = $cache->get('geo:' . $ip);
     if ($cache->wasResultFound()) {
         if (DEBUG_BAR) {
             Bootstrap::getInstance()->debugbar['messages']->addMessage("Cached GeoInfo: {$ip}");
         }
         return $return;
     }
     $client = new \GuzzleHttp\Client();
     //'https://geoip.maxmind.com/geoip/v2.1/city/me
     $res = $client->get($this->url . $ip, array('auth' => array($this->user, $this->password)));
     $body = $res->getBody(true);
     $json = json_decode($body);
     $return = array('countryCode' => $json->country->iso_code, 'countryName' => $json->country->names->en, 'state' => $json->subdivisions[0]->names->en, 'city' => $json->city->names->en);
     if (empty($return['city'])) {
         $return['city'] = 'Unknown';
     }
     if (empty($return['state'])) {
         $return['state'] = 'Unknown';
     }
     $cache->set('geo:' . $ip, $return, 3600);
     return $return;
 }
开发者ID:ligerzero459,项目名称:block-explorer,代码行数:25,代码来源:MaxMind.php

示例3: remove

 /**
  * Unlock
  */
 public function remove()
 {
     if ($this->key and Cache::getInstance()->get($this->key) == $this->rnd) {
         Cache::getInstance()->remove($this->key);
         $this->key = null;
     }
 }
开发者ID:difra-org,项目名称:difra,代码行数:10,代码来源:Locker.php

示例4: testSetValueWithoutNamespaceWorks

 public function testSetValueWithoutNamespaceWorks()
 {
     $cache = Cache::getInstance(array('driver' => 'array'));
     $cache->setNamespace('namespace', true);
     $cache->set('foo', 'bar');
     $this->assertEquals('bar', $cache->get('foo'));
 }
开发者ID:escapework,项目名称:cache,代码行数:7,代码来源:CacheTest.php

示例5: _index

 public function _index()
 {
     $search = $_GET['search_field'];
     if (empty($search) || $search == "图片/作者/画集") {
         echo "<script>history.back(-1);</script>";
     }
     //查找用户
     $user = new user();
     $usersearch = $user->model->Get('all', array("NickName` LIKE '%{$search}%"), array(0, 5));
     if (empty($usersearch)) {
         $searchuser = "<h3>没有找到相关用户</h3>";
     }
     foreach ($usersearch as $userresult) {
         $username = $userresult->NickName;
         $userid = $userresult->UserId;
         $searchuser .= '<div style="width:180px;float:left;"><div style="float:left"><a href="/user/' . $userid . '" title="' . $username . '"><img src="/upload/avatar_small/' . $userid . '_small.jpg"/></a></div><a href="/user/' . $userid . '" title="' . $username . '"><h4 style="color:#09F;">' . $username . '</h4></a></div>';
     }
     //查找标签
     $mem = Cache::getInstance();
     $tagdef = new tagdefine();
     $tags = $tagdef->model->Get('all', array("TagName` LIKE '%{$search}%"), array(0, 5));
     if (empty($tags)) {
         $tagline = "<h3>没有找到相关标签</h3>";
     }
     foreach ($tags as $tag) {
         $tagname = $tag->TagName;
         $postings = $mem->get($tagname);
         //var_dump($postings);
         $image = new image();
         $image->model->lockMutiQuery();
         foreach ($postings as $key => $value) {
             $image->model->Get_By_ImageId($key);
         }
         $image->model->MultiQuery();
         $imgs = $image->model->getresult();
         $favor = new favourite();
         $tagline .= '<div class="tagsinput"><a href="/tag/' . $tagname . '"><span class="tag"><span>' . $tagname . '&nbsp;&nbsp;</span></span></a>';
         foreach ($imgs as $r2) {
             //var_dump($r2);
             $tagline .= '<div style="margin:8px;"><div><a href="/files/' . $r2->imgurl . ' "><img src="/thumbnails/' . $r2->imgurl . '"/></a></div><div><a href="/user/' . $r2->author . '">' . $r2->user->NickName . '</a></br>描述:' . $r2->Description . '</div></div>';
         }
     }
     //查找画集
     $imggroup = new imagegroup();
     $searchgroup = $imggroup->model->Get('all', array("GroupName` LIKE '%{$search}%"), array(0, 5));
     if (empty($searchgroup)) {
         $groupline = "<h3>没有相关的画集</h3>";
     }
     $image = new image();
     foreach ($searchgroup as $groups) {
         $id = $groups->ImagegroupId;
         $imgs = $image->model->Get('all', array("GroupId={$id}"), array(0, 1));
         foreach ($imgs as $img) {
             $imgurl = rawurlencode($img->imgurl);
         }
         $groupline .= '<div><div><a href="/imagegroup/' . $id . '"><img src="/thumbnails/' . $imgurl . '"/></a></div><div><b>' . $groups->GroupName . '</b></br>' . $groups->user->NickName . '</div></div>';
     }
     $this->values = array("searchuser" => $searchuser, "title" => "搜索:{$search}", "searchtext" => $search, "searchtag" => $tagline, "searchgroup" => $groupline);
     $this->RenderTemplate('index');
 }
开发者ID:RaoHai,项目名称:picpic,代码行数:60,代码来源:controller.search.class.php

示例6: setNodes

 /**
  * Sets the nodes to work with.
  * @param array $nodes
  *
  * @return integer Number of nodes added.
  */
 public function setNodes(array $nodes)
 {
     $cache = Cache::getInstance();
     $available_servers = trim($cache->get($this->loadbalancer_cache_key));
     // CacheDisk returns " " when no cache.
     if (empty($available_servers)) {
         foreach ($nodes as $key => $node_properties) {
             $this->addNodeIfAvailable($key, $node_properties);
         }
         // Save in cache available servers (even if none):
         $serialized_nodes = serialize(array('nodes' => $this->nodes, 'total_weights' => $this->total_weights));
         $cache->set($this->loadbalancer_cache_key, $serialized_nodes, self::CACHE_EXPIRATION);
     } else {
         $available_servers = unserialize($available_servers);
         $this->nodes = $available_servers['nodes'];
         $this->total_weights = $available_servers['total_weights'];
     }
     $num_nodes = count($this->nodes);
     if (1 > $num_nodes) {
         // This exception will be shown for CACHE_EXPIRATION seconds until servers are up again.
         $message = "No available servers in profile";
         trigger_error($message);
         throw new Exception_500($message);
     }
     return $num_nodes;
 }
开发者ID:ninodafonte,项目名称:SIFO,代码行数:32,代码来源:LoadBalancer.php

示例7: display

 function display($params)
 {
     $Log_Model = new Log_Model();
     $CACHE = Cache::getInstance();
     $options_cache = Option::getAll();
     extract($options_cache);
     $page = isset($params[4]) && $params[4] == 'page' ? abs(intval($params[5])) : 1;
     $author = isset($params[1]) && $params[1] == 'author' ? intval($params[2]) : '';
     $pageurl = '';
     $user_cache = $CACHE->readCache('user');
     if (!isset($user_cache[$author])) {
         show_404_page();
     }
     $author_name = $user_cache[$author]['name'];
     //page meta
     $site_title = $author_name . ' - ' . $site_title;
     $sqlSegment = "and author={$author} order by date desc";
     $sta_cache = $CACHE->readCache('sta');
     $lognum = $sta_cache[$author]['lognum'];
     $total_pages = ceil($lognum / $index_lognum);
     if ($page > $total_pages) {
         $page = $total_pages;
     }
     $start_limit = ($page - 1) * $index_lognum;
     $pageurl .= Url::author($author, 'page');
     $Log_Model = new Log_Model();
     $logs = $Log_Model->getLogsForHome($sqlSegment, $page, $index_lognum);
     $page_url = pagination($lognum, $index_lognum, $page, $pageurl);
     include View::getView('header');
     include View::getView('log_list');
 }
开发者ID:MikeCoder,项目名称:mblog,代码行数:31,代码来源:author_controller.php

示例8: S

function S($name, $value = '', $expire = '', $type = '', $options = null)
{
    static $_cache = array();
    alias_import('Cache');
    //取得缓存对象实例
    $cache = Cache::getInstance($type, $options);
    if ('' !== $value) {
        if (is_null($value)) {
            // 删除缓存
            $result = $cache->rm($name);
            if ($result) {
                unset($_cache[$type . '_' . $name]);
            }
            return $result;
        } else {
            // 缓存数据
            $cache->set($name, $value, $expire);
            $_cache[$type . '_' . $name] = $value;
        }
        return;
    }
    if (isset($_cache[$type . '_' . $name])) {
        return $_cache[$type . '_' . $name];
    }
    // 获取缓存数据
    $value = $cache->get($name);
    $_cache[$type . '_' . $name] = $value;
    return $value;
}
开发者ID:Trangttq,项目名称:thinkphp-vietnam,代码行数:29,代码来源:functions.php

示例9: getAll

 static function getAll()
 {
     $CACHE = Cache::getInstance();
     $options_cache = $CACHE->readCache('options');
     $options_cache['site_title'] = $options_cache['site_title'] ? $options_cache['site_title'] : $options_cache['blogname'];
     $options_cache['site_description'] = $options_cache['site_description'] ? $options_cache['site_description'] : $options_cache['bloginfo'];
     return $options_cache;
 }
开发者ID:MikeCoder,项目名称:mblog,代码行数:8,代码来源:option.php

示例10: deleteAll

 function deleteAll($conditions, $params = array())
 {
     if (!empty($this->cache) and Base::getConfig('cache') >= 1 and Base::getConfig('cache_query') >= 1) {
         $cache = Cache::getInstance($this->tablename . '.queries');
         $cache->destroy();
     }
     return parent::deleteAll($conditions, $params);
 }
开发者ID:ejailesb,项目名称:repo_empr,代码行数:8,代码来源:gmodel.php

示例11: _initialize

 public function _initialize()
 {
     //$this->cache = Cache::getInstance('File', array('expire' => '60'));
     $s = microtime(1);
     //localhost 超级慢 ?
     $this->cache = Cache::getInstance('Redis');
     $e = microtime(1);
     //echo $e - $s;
 }
开发者ID:qihaier,项目名称:think,代码行数:9,代码来源:CacheAction.class.php

示例12: performOp

 /**
  * 性能优化
  */
 public function performOp()
 {
     if ($_GET['type'] == 'clear') {
         $lang = Language::getLangContent();
         $cache = Cache::getInstance(C('cache.type'));
         $cache->clear();
         showMessage($lang['nc_common_op_succ']);
     }
     Tpl::showpage('setting.perform_opt');
 }
开发者ID:norain2050,项目名称:xingkang,代码行数:13,代码来源:perform.php

示例13: __callstatic

 public static function __callstatic($method, $args)
 {
     if (self::$handler === null) {
         Cache::getInstance(C('CACHE_DRIVER', null, 'memcache'));
     }
     //调用缓存驱动的方法
     if (method_exists(self::$handler, $method)) {
         return call_user_func_array(array(self::$handler, $method), $args);
     }
 }
开发者ID:oohook,项目名称:PTFrameWork,代码行数:10,代码来源:cache.php

示例14: GetFromCached

 public static function GetFromCached()
 {
     $mem = Cache::getInstance();
     if (!$mem->get("allow")) {
         return false;
     }
     self::$allow = $mem->get("allow");
     self::$parents = $mem->get("parents");
     self::$Rolelist = $mem->get("role");
 }
开发者ID:RaoHai,项目名称:picpic,代码行数:10,代码来源:acl.php

示例15: __construct

 public function __construct($config)
 {
     $redis_config = array('tcp' => $config->redis->tcp, 'host' => $config->redis->host, 'port' => $config->redis->port, 'database' => $config->redis->database);
     $this->_redis_handler = Cache::getInstance($redis_config);
     //session前缀
     if (isset($config->redis->cache_key_prefix)) {
         $this->_cache_key_prefix = $config->redis->cache_key_prefix;
     }
     parent::__construct();
 }
开发者ID:hexcode007,项目名称:yfcms,代码行数:10,代码来源:memcacheHandler.php


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