Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Memcache Start vs. Save

I am having some trouble trying to make a cacheableModel, when ever I try to save to cache (memcache), I get an error: "The cache must be started first"? My Frontend is Data, and the backend is memcache. Is there something I am not getting?



1.7k
edited Aug '14

This is the code in the Model, where I extend override findFirts()

public static function findFirst($params = null)
{
        $key = self::createKey($params);
        $di = Phalcon\Di::getDefault()->get('modelsCache');
        $cacheResults = $di->get($key);
        if (isset($cacheResults)) {
            return $cacheResults;
        }
        $result = parent::findFirst($params);
        $di->save($key, $result);
        return $result;
}


1.7k
Accepted
answer

Okay, I found the issue,

Other controllers were also extending this model, and createKey() function didn't cater for their params.

edited Aug '14

For next It is not good practice to cache rows by your hands (your redeclare method)

Use something like this

$products = Products::find(array(
    "cache" => array("key" => "my-cache", "lifetime" => 300)
));


1.7k

Thanks, implemented that now.