cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[2.0.1]Cache bug

Open eclipse88 opened this issue 11 years ago • 10 comments

$frontCache = new \Phalcon\Cache\Frontend\Data(array(
        'lifetime' => 3600 * 24
    ));

    $cache = new Phalcon\Cache\Backend\File($frontCache, array(
        "cacheDir" => "../cache/",
    ));

$object; //a big object
$cache->save('asd', $object);

return $object->toArray()//first time returning an empty array

i tried with \Backend\File and \Backend\Redis and same result an empty array

eclipse88 avatar May 15 '15 13:05 eclipse88

Where does $object comes from? What kind of object or instance of what class is it?

andresgutierrez avatar May 18 '15 14:05 andresgutierrez

an object like this:

$robots = Robots::find();

In my case i have a table with 50 columns, and for example if i query more than 2000 rows, first time when create the cache if i try to call method $object->toArray() is an empty array. This is happening when is a lot of data, and first time when create the cache, next request will return the results from cache if i comment this line $cache->save('asd', $robots ); is working

eclipse88 avatar May 18 '15 14:05 eclipse88

CREATE TABLE IF NOT EXISTS Zones ( id int(11) NOT NULL AUTO_INCREMENT, name varchar(50) NOT NULL, coordinates text NOT NULL PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

for($i = 0; $i < 1000; $i++){
            $zone = new Zones();
            $z = [
                'name' => 'asd',
                'coordinates' => 'asdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdqwefrwegwerhrthjrthjasdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdqwefrwegwe
                    rhrthjrthjasdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdqwefrwegwerhrthjrthjasdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdqwefrwegwerhrthjrthjas
                    dasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaasdqwefrwegwerhrthjrthjasdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdqwefrwegwerhrthjrthjasdasdaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    asdqwefrwegwerhrthjrthjasdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdqwefrwegwerhrthjrthjasdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdqwefrwegwerhrth
                    jrthjasdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaasdqwefrwegwerhrthjrthjasdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdqwefrwegwerhrthjrthjasdasdaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaasdqwefrwegwerhrthjrthjasdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdqwefrwegwerhrthjrthjasdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdqwefrwegwerhrth
                    jrthjasdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaasdqwefrwegwerhrthjrthjasdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdqwefrwegwerhrthjrthj',

            ];
            $zone->assign($z);
            $zone->save();

        }

        $zones = Zones::find();
        //$zones = Zones::find(array("limit" => 30)); if you try with limit <=30 will work
        $frontCache = new \Phalcon\Cache\Frontend\Data(array(
            'lifetime' => 3600 * 24
        ));

        $cache = new Phalcon\Cache\Backend\File($frontCache, array(
            "cacheDir" => "../app/cache/",
            //"prefix" => $config->environment
        ));
        $cache->save('zones', $zones);//if comment this line is working

        var_dump($zones->toArray()); //return empty array

is a problem when is a lot of information in object

eclipse88 avatar May 21 '15 07:05 eclipse88

I have same issue! It happens in all cache backends

Sad!

sszdh avatar May 25 '15 18:05 sszdh

I have users table with over 8 million records. If I use File backend or Memory (for development purposes) I have big overhead. Loops through table approximately at 20,000 line eating up all available memory.

@andresgutierrez Did you take MetaData and Cache performance tests for really big data?

sergeyklay avatar May 25 '15 20:05 sergeyklay

@sergeyklay Serialize a 20.000 records resulset is slow in any language, not sure if you might need to rethink your architecture

andresgutierrez avatar May 25 '15 20:05 andresgutierrez

Any one here, use phalcon Cache in a real app?

If I could not cache a big resultset, so what is the popose of cache system anymore?

sszdh avatar May 25 '15 22:05 sszdh

@sszdh You use a cache to avoid hit the database, but PHP only understand their own native structures, you have to fetch the full resultset to the main memory every time.

andresgutierrez avatar May 25 '15 22:05 andresgutierrez

@andresgutierrez You'r right, but in this example, fetched result suddenly gets empty after saving to cache!

So, there is no resultset exists anymore to fetch to the memory at all, atleast in first refresh.

in zep source code, every thing seems OK and logical but result is not...

\Phalcon\Mvc\Model\Query::execute()

sszdh avatar May 25 '15 23:05 sszdh

in my example if you have 50 records the array is empty, this is definitely a problem.

eclipse88 avatar May 26 '15 08:05 eclipse88