在CodeIgniter 3.0中使用Memcached

时间:2015-07-03 11:23:54

标签: php codeigniter memcached

这是我的模型文件;

function yaklasan_maclar_tenis() {
           $data = $this->cache->memcached->get('yaklasan_tenis');
           if (!$data){
              $this -> db -> limit(10);
              $data = array();
              foreach ($this->db->get_where('maclar', array('durum' => '1', 'sonuclandi' => '0', 'tarih >=' => time(), 'spor' => '5'))->result_array() as $row) {
                $data[] = array(
                'id' => $row['id'],
                'matchid' => $row['matchid'],
                'spor' => $row['spor'],
                'ulke' => $row['ulke'],
                'turnuva' => $row['turnuva'],
                'takim1' => $row['takim1'],
                'takim2' => $row['takim2'],
                'tarih' => $row['tarih'],
                'istatistik' => $row['istatistik'],

                );
            }
              $this->cache->memcached->save('yaklasan_tenis',$data, 600);
           }
           return $data;
    }

我确定我正确安装了memcached,但在调用此函数时出现此错误:

Fatal error: Call to a member function get() on a non-object in /home/mydomain/public_html/system/libraries/Cache/drivers/Cache_memcached.php on line 79

以下是第77-82行,Cache_memcached.php文件:

public function get($id)
    {
        $data = $this->_memcached->get($id); //this line is 79

        return is_array($data) ? $data[0] : $data;
    }

我在网站上进行了研究,但却找不到任何相关信息。我刚刚找到了一些东西并尝试了这个建议但没有改变。

提前致谢。

1 个答案:

答案 0 :(得分:0)

您是否加载了缓存驱动器?

喜欢的东西:

$this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));