Welcome Guest, Not a member yet? Register   Sign In
Moving from Zend Memcache
#1

[eluser]RaZoR LeGaCy[/eluser]
Looking to move from using Zend Framework Memcache but need help with class.

I have models that use pre-existing code and need to stay that way. The old code uses Cache::init($lifetime of cache); so I need to keep it this way. Problem is, I cannot get the $_cache variable and the $lifetime variable into the save function.

I try $this-> and it says "Using $this when not in object context" and when using $lifetime, is says "Undefined variable: lifetime"; the same for $_cache

Code:
class Cache
{
   public $_cache;
   public $lifetime;

    //static protected $_cache;

    function init($lifetime=3600) {
      $_cache = new Memcache;
      $_cache->addServer('127.0.0.1', 11211);
   }

    static function getInstance() {
        return self::$_cache;
    }
    
    static function save($key, $value) {
       return $_cache->set($key, $value, 0, time()+$lifetime);
    }
}

What is wrong here?
#2

[eluser]RaZoR LeGaCy[/eluser]
Code:
function cache(){
  Cache::init(360); // 6 Min Cache
    $keyName = 'test_new_cache'; // unique name describing this data set
    $data = Cache::load($keyName);
    if($data === false) {
      $data = array('test1' => '123',);
      Cache::save($keyName, $data);
    }
    return $data;
}
#3

[eluser]RaZoR LeGaCy[/eluser]
I changed to APC which is better and much easier to implement.

Still would like to know what I did wrong.




Theme © iAndrew 2016 - Forum software by © MyBB