Welcome Guest, Not a member yet? Register   Sign In
How to use cache
#1

[eluser]Unknown[/eluser]
I write a simple code but my cache not showing anyway

Code:
<?php

class caching extends CI_Controller{
function  __construct() {
    parent::__construct();
    $this->load->driver('cache');
    
    }
    function index(){
      

$this->cache->save('cache_item_id', 'data_to_cache');
echo $this->cache->get('cache_item_id');

    }
    

      


}

?>
#2

[eluser]ChrisMiller[/eluser]
You are using it wrong in a bit of a way...

Code:
<?php

class caching extends CI_Controller{
    function  __construct()
    {
        parent::__construct();
        $this->load->driver('cache');
    }

    function index()
    {
        // Attempt to get the item
        if( ! $item = $this->cache->get('item') )
        {
            // No Luck so save it again
            // Save into the cache for 5 minutes
            $this->cache->save('item', 'Some Value', 300);

        }

        // Output Item
        echo $item;
    }

}




Theme © iAndrew 2016 - Forum software by © MyBB