CodeIgniter APC Cache无法获取GET

时间:2017-08-01 06:10:27

标签: codeigniter caching fetch apc

我搜索了整个互联网,无法解决为什么CodeIgniter 3中的缓存GET不起作用。

这个函数,ADD和GET一起生成sin,按预期工作并在获取后显示缓存:

public function apc_add_and_get()
  {
    # load Cache driver using APC, failover to file caching, and prefix the cache
    $this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file', 'key_prefix' => ''));

    $data = array(
      'CI Admins' => array(
        'CI Admin' => array(
          'name' => 'John',
          'site' => 'https://www.example.com'
        )
      ), 
      'CI users' => array(
        'CI user' => array(
          'name' => 'Sally',
          'site' => 'https://www.another.com'
        )
      ),    
    );

    // Save into the cache for 5 minutes
    $this->cache->save('foo', $data, 300);

    echo '<p><pre>';
    var_dump($this->cache->get('foo')); // get the cache entry named 'foo'
    echo '</pre></p>';
  }

为什么当我将ADD和GET分成下面显示的单独的函数时, GET 是否返回FALSE?

public function apc_add()
  {
    # load Cache driver using APC, failover to file caching, and prefix the cache
    $this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file', 'key_prefix' => ''));

    $data = array(
      'CI Admins' => array(
        'CI Admin' => array(
          'name' => 'John',
          'site' => 'https://www.example.com'
        )
      ), 
      'CI users' => array(
        'CI user' => array(
          'name' => 'Sally',
          'site' => 'https://www.another.com'
        )
      ),    
    );

    // Save into the cache for 5 minutes
    $this->cache->save('foo', $data, 300);

  }

public function apc_get()
  {
    # load Cache driver using APC, failover to file caching, and prefix the cache
    $this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file', 'key_prefix' => ''));

    echo '<p><pre>';
    var_dump($this->cache->get('foo')); // get the cache entry named 'foo'
    echo '</pre></p>';
  }

服务器错误日志和CodeIgniter错误日志都没有显示任何问题。

目标是将大量常量保存到缓存中。在此之后运行程序时,它将从缓存中检索值。所以,我会调用ADD函数一次来创建缓存,每次运行程序时,我都会调用GET函数。

(这样做可以节省我的三个用户毫秒/年;这就是我花了超过 10小时的原因: - )

我的理智等待着你最优秀的建议!

VITAL STATS:

    CodeIgniter 3.1.5
    GoDaddy shared Linux hosting
    PHP 5.3.24
    APC is enabled

CodeIgniter手册页:https://www.codeigniter.com/user_guide/libraries/caching.html

0 个答案:

没有答案