Model find with cache in controller initialize()

Hi,

Why model's caching does not work in controller initialize() method?

I've a BaseController as follow:

class Base extends PhController
{
    /**
     * Initializes the controller
     */
    public function initialize()
    {
        $this->view->setVar('categories', Categories::find(array(
                "cache" => array("key" => "categories")
            ))->toArray());
    }
...
}

But in first request categories array is empty and if I fills correctly from cache. cache file also creates in first request dispatch but resultset in empty.

Sorry about my bad english!

Thanks

edited May '15

Uhh, I found the problem. It's not about controllers!

It seems that the problem is in the file cache process and number of data you want to cache. If number of fetched rows are small it works (about 30 rows) and if result goes biger then writing to file take longer time and cache return empty data. I have search source files but with no success!

File caching looks asyncuronus process. Anyone knows somthing about that?

UPDATE: It happens in Memechace too!! For first time nothing returns back from cache!

Thanks.

Hi,

Type checking for big resultset (> 32): (https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/mvc/model/resultset/simple.zep#L75)

The Doc mentions as folow:

Storing large query results in memory could consume many resources, because of this, resultsets are obtained from the database in chunks of 32 rows reducing the need for re-execute the request in several cases also saving memory. Note that resultsets can be serialized and stored in a cache backend. Phalcon\Cache can help with that task. However, serializing data causes Phalcon\Mvc\Model to retrieve all the data from the database in an array, thus consuming more memory while this process takes place.

But question is: Why phalcon returns empty array after cacheing results greater than 32 rows?

And finaly this is interesting part of source about toArray() function: It seems that the else block reaches (line 186) because typeof chached resultset is not object at moment!

(https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/mvc/model/resultset/simple.zep#L183)

Regards

Could you please post this as a comment in here: https://github.com/phalcon/cphalcon/issues/10392 ?

Hi,

Type checking for big resultset (> 32): (https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/mvc/model/resultset/simple.zep#L75)

The Doc mentions as folow:

Storing large query results in memory could consume many resources, because of this, resultsets are obtained from the database in chunks of 32 rows reducing the need for re-execute the request in several cases also saving memory. Note that resultsets can be serialized and stored in a cache backend. Phalcon\Cache can help with that task. However, serializing data causes Phalcon\Mvc\Model to retrieve all the data from the database in an array, thus consuming more memory while this process takes place.

But question is: Why phalcon returns empty array after cacheing results greater than 32 rows?

And finaly this is interesting part of source about toArray() function: It seems that the else block reaches (line 186) because typeof chached resultset is not object at moment!

(https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/mvc/model/resultset/simple.zep#L183)

Regards

@andresgutierrez Sure.

Could you please post this as a comment in here: https://github.com/phalcon/cphalcon/issues/10392 ?

Hi,

Type checking for big resultset (> 32): (https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/mvc/model/resultset/simple.zep#L75)

The Doc mentions as folow:

Storing large query results in memory could consume many resources, because of this, resultsets are obtained from the database in chunks of 32 rows reducing the need for re-execute the request in several cases also saving memory. Note that resultsets can be serialized and stored in a cache backend. Phalcon\Cache can help with that task. However, serializing data causes Phalcon\Mvc\Model to retrieve all the data from the database in an array, thus consuming more memory while this process takes place.

But question is: Why phalcon returns empty array after cacheing results greater than 32 rows?

And finaly this is interesting part of source about toArray() function: It seems that the else block reaches (line 186) because typeof chached resultset is not object at moment!

(https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/mvc/model/resultset/simple.zep#L183)

Regards