Welcome Guest, Not a member yet? Register   Sign In
Cache_Lite for CI
#1

[eluser]Unknown[/eluser]
This is Cache_Lite for CodeIgniter from PEAR.

I renamed base class:

class cacher ...

New constructor:

Code:
function cacher($options = array(NULL))
    {
        foreach($options as $key => $value) {
            $this->setOption($key, $value);
        }
        
        if (@($options['cacheDir'])=='') $this->_cacheDir=BASEPATH.'cache/';
    }

Example:

Code:
function customersCount()
    {
        
        if ($count=$this->cacher->get('customersCount')){
            
            //cached data
            return $count;
            
        } else {
        
            $this->db->select('count(id) as ocount');
            $this->db->where('type=','customer');
            $this->db->from('users');

            $query=$this->db->get(); $row=$query->row();
            
            if (isset($row->ocount)){
              
               $this->cacher->setLifeTime(1000);
               $this->cacher->save($row->ocount);

               return $row->ocount;
            }

            return 0;
        }
    }

Download cache_lite for CI
#2

[eluser]xwero[/eluser]
I think you better add more checks instead of suppressing errors with the at character, it tends to slow down the application.
#3

[eluser]Unknown[/eluser]
Thank you, I posted new example!




Theme © iAndrew 2016 - Forum software by © MyBB