當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。