CodeIgniter Forums
Cache_Lite for CI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Cache_Lite for CI (/showthread.php?tid=5410)



Cache_Lite for CI - El Forum - 01-21-2008

[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


Cache_Lite for CI - El Forum - 01-21-2008

[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.


Cache_Lite for CI - El Forum - 01-21-2008

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