<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 緩存驅動器 CodeIgniter 提供了幾種最常用的快速緩存的封裝,除了基于文件的緩存, 其他的緩存都需要對服務器進行特殊的配置,如果配置不正確,將會拋出 一個致命錯誤異常(Fatal Exception)。 [TOC] ## 使用示例 下面的示例代碼用于加載緩存驅動器,使用?[APC](http://codeigniter.org.cn/user_guide/libraries/caching.html#alternative-php-cache-apc-caching)?作為緩存, 如果 APC 在服務器環境下不可用,將降級到基于文件的緩存。 ~~~ $this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file')); if ( ! $foo = $this->cache->get('foo')) { echo 'Saving to the cache!<br />'; $foo = 'foobarbaz!'; // Save into the cache for 5 minutes $this->cache->save('foo', $foo, 300); } echo $foo; ~~~ 你也可以設置?**key_prefix**?參數來給緩存名添加前綴,當你在同一個環境下運行多個應用時,它可以避免沖突。 ~~~ $this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file', 'key_prefix' => 'my_') ); $this->cache->get('foo'); // Will get the cache entry named 'my_foo' ~~~ ## 類參考 classCI_Cache >[info] ### is_supported($driver) 參數: * **$driver**?(string) -- the name of the caching driver 返回: TRUE if supported, FALSE if not 返回類型: bool 當使用?$this->cache->get()?方法來訪問驅動器時該方法會被自動調用,但是,如果你使用了某些個人的驅動器, 應該先調用該方法確保這個驅動器在服務器環境下是否被支持。 ~~~ if ($this->cache->apc->is_supported()) { if ($data = $this->cache->apc->get('my_cache')) { // do things. } } ~~~ >[info] ### get($id) 參數: * **$id**?(string) -- Cache item name 返回: Item value or FALSE if not found 返回類型: mixed 該方法用于從緩存中獲取一項條目,如果獲取的條目不存在,方法返回 FALSE 。 ~~~ $foo = $this->cache->get('my_cached_item'); ~~~ >[info] ### save($id,?$data[,?$ttl = 60[,?$raw = FALSE]]) 參數: * **$id**?(string) -- Cache item name * **$data**?(mixed) -- the data to save * **$ttl**?(int) -- Time To Live, in seconds (default 60) * **$raw**?(bool) -- Whether to store the raw value 返回: TRUE on success, FALSE on failure 返回類型: string 該方法用于將一項條目保存到緩存中,如果保存失敗,方法返回 FALSE 。 ~~~ $this->cache->save('cache_item_id', 'data_to_cache'); ~~~ > 注解 > 參數?$raw?只有在使用 APC 和 Memcache 緩存時才有用, 它用于?increment()?和?decrement()?方法。 >[info] ### delete($id) 參數: * **$id**?(string) -- name of cached item 返回: TRUE on success, FALSE on failure 返回類型: bool 該方法用于從緩存中刪除一項指定條目,如果刪除失敗,方法返回 FALSE 。 ~~~ $this->cache->delete('cache_item_id'); ~~~ >[info] ### increment($id[,?$offset = 1]) 參數: * **$id**?(string) -- Cache ID * **$offset**?(int) -- Step/value to add 返回: New value on success, FALSE on failure 返回類型: mixed 對緩存中的值執行原子自增操作。 ~~~ // 'iterator' has a value of 2 $this->cache->increment('iterator'); // 'iterator' is now 3 $this->cache->increment('iterator', 3); // 'iterator' is now 6 ~~~ >[info] ### decrement($id[,?$offset = 1]) 參數: * **$id**?(string) -- Cache ID * **$offset**?(int) -- Step/value to reduce by 返回: New value on success, FALSE on failure 返回類型: mixed 對緩存中的值執行原子自減操作。 ~~~ // 'iterator' has a value of 6 $this->cache->decrement('iterator'); // 'iterator' is now 5 $this->cache->decrement('iterator', 2); // 'iterator' is now 3 ~~~ >[info] ### clean() 返回: TRUE on success, FALSE on failure 返回類型: bool 該方法用于清空整個緩存,如果清空失敗,方法返回 FALSE 。 ~~~ $this->cache->clean(); ~~~ >[info] ### cache_info() 返回: Information on the entire cache database 返回類型: mixed 該方法返回整個緩存的信息。 ~~~ var_dump($this->cache->cache_info()); ~~~ > 注解 > 返回的信息以及數據結構取決于使用的緩存驅動器。 >[info] ### get_metadata($id) 參數: * **$id**?(string) -- Cache item name 返回: Metadata for the cached item 返回類型: mixed 該方法用于獲取緩存中某個指定條目的詳細信息。 ~~~ var_dump($this->cache->get_metadata('my_cached_item')); ~~~ > 注解 > 返回的信息以及數據結構取決于使用的緩存驅動器。 ## 驅動器 ### 可選 PHP 緩存(APC) 上述所有方法都可以直接使用,而不用在加載驅動器時指定 adapter 參數,如下所示: ~~~ $this->load->driver('cache'); $this->cache->apc->save('foo', 'bar', 10); ~~~ 關于 APC 的更多信息,請參閱?[http://php.net/apc](http://php.net/apc) ### 基于文件的緩存 和輸出類的緩存不同的是,基于文件的緩存支持只緩存視圖的某一部分。使用這個緩存時要注意, 確保對你的應用程序進行基準測試,因為當磁盤 I/O 頻繁時可能對緩存有負面影響。 上述所有方法都可以直接使用,而不用在加載驅動器時指定 adapter 參數,如下所示: ~~~ $this->load->driver('cache'); $this->cache->file->save('foo', 'bar', 10); ~~~ ### Memcached 緩存 可以在 memcached.php 配置文件中指定多個 Memcached 服務器,配置文件位于?application/config/?目錄。 上述所有方法都可以直接使用,而不用在加載驅動器時指定 adapter 參數,如下所示: ~~~ $this->load->driver('cache'); $this->cache->memcached->save('foo', 'bar', 10); ~~~ 關于 Memcached 的更多信息,請參閱?[http://php.net/memcached](http://php.net/memcached) ### WinCache 緩存 在 Windows 下,你還可以使用 WinCache 緩存。 上述所有方法都可以直接使用,而不用在加載驅動器時指定 adapter 參數,如下所示: ~~~ $this->load->driver('cache'); $this->cache->wincache->save('foo', 'bar', 10); ~~~ 關于 WinCache 的更多信息,請參閱?[http://php.net/wincache](http://php.net/wincache) ### Redis 緩存 Redis 是一個在內存中以鍵值形式存儲數據的緩存,使用 LRU(最近最少使用算法)緩存模式, 要使用它,你需要先安裝?[Redis 服務器和 phpredis 擴展](https://github.com/phpredis/phpredis)。 連接 Redis 服務器的配置信息必須保存到 application/config/redis.php 文件中,可用參數有: ~~~ $config['socket_type'] = 'tcp'; //`tcp` or `unix` $config['socket'] = '/var/run/redis.sock'; // in case of `unix` socket type $config['host'] = '127.0.0.1'; $config['password'] = NULL; $config['port'] = 6379; $config['timeout'] = 0; ~~~ 上述所有方法都可以直接使用,而不用在加載驅動器時指定 adapter 參數,如下所示: ~~~ $this->load->driver('cache'); $this->cache->redis->save('foo', 'bar', 10); ~~~ 關于 Redis 的更多信息,請參閱?[http://redis.io](http://redis.io/) ### 虛擬緩存(Dummy Cache) 這是一個永遠不會命中的緩存,它不存儲數據,但是它允許你在當使用的緩存在你的環境下不被支持時, 仍然保留使用緩存的代碼。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看