@ https://ellislab.com/codeigniter/user-guide/libraries/caching.html
$this->load->driver('cache');
$this->cache->memcached->save('foo', 'bar', 10);
後來我自己去 trace 原始碼才知道該怎樣設定跟測試。首先,新增一個設定檔:
$ vim application/config/memcached.php
$config['memcached'] = array(
'hostname' => 'Your_memecached_cluster',
'port' => 11211,
'weight' => 1
);
接著,使用:
class My_Library {
public function __construct() {
$this->ci =& get_instance();
$this->init();
}
public function init() {
$this->ci->load->driver('cache');
return $this->ci->cache->is_supported('memcached');
}
public function set($key, $value, $tts) {
return $this->ci->cache->memcached->save($key, $value, $tts);
}
public function delete($key) {
$this->ci->cache->memcached->delete($key);
}
}
關鍵之處就是要呼叫 $this->ci->cache->is_supported('memcached') 這段,才會從 application/config/memcached.php 把資訊更新進來 Orz
若需要 debug 的話:
$ find . -name "*mem*"
./system/libraries/Cache/drivers/Cache_memcached.php
找到 $this->_memcached 可以善用它,例如 $this->_memcached->getResultCode();
https://github.com/CodeIgniter-TW/CodeIgniter-UserGuide
回覆刪除大大CodeIgniter 3.0 需要人手幫忙翻譯,不知大大您願意嗎?
回覆刪除https://github.com/CodeIgniter-TW/CodeIgniter-UserGuide
感謝邀請 :D
刪除只是有太多好玩得事,時間不夠 XDD
我有空會再去看看的,現況寫 code 還是比翻譯快樂許多