【问题标题】:Cache problem with CodeIgniterCodeIgniter 的缓存问题
【发布时间】:2011-08-08 17:05:22
【问题描述】:

我在 CodeIgniter 中的缓存有问题。

然后我下载了CodeIgniter的缓存库并放入libraries文件夹中,并将php代码放入控制器文件中:

<?php

class Cache extends CI_Controller
{
    public function index()
    {
        $this->cache->set('test_cache', 'test_cache_content', 300); // 5 minutes
    }
}

?>

test_cache 缓存文件不在缓存文件夹中。在 config.php 文件中 cache_path 是默认的。

然后我想获取 test_cache 内容并将代码放入控制器中:

<?php

class Cache extends CI_Controller
{
    public function get()
    {
        $data = $this->cache->get('test_cache');
        echo var_dump($data);
    }
}

?>

然后我看到 null。我在codeigniter中搜索缓存,但没有。

【问题讨论】:

    标签: caching codeigniter


    【解决方案1】:

    只是为了确保,因为它实际上不在上面的代码中,所以您确实加载了一个缓存驱动程序,对吧:

    // example from CodeIgniter Cache docs.
    $this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
    

    因为如果你没有它默认为虚拟驱动程序。虚拟驱动程序不会保存任何内容,所以我认为您不希望这样做。

    【讨论】:

    • 我不明白如何在 CodeIgniter 中使用缓存方法。你能帮助我吗?如何加载缓存?如何保存缓存文件?如何获取保存的文件内容?
    猜你喜欢
    • 1970-01-01
    • 2012-12-27
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    • 1970-01-01
    • 2015-07-02
    相关资源
    最近更新 更多