Activerecord Cache
#1
Posted 27 December 2012 - 04:42 AM
$series = Post::model()->cache(3600)->getPopularPosts(5);
I see in my webLogRoute that it only saves the cache every time, but it never loads it from the cache, why not?
#2
Posted 27 December 2012 - 05:13 AM
check this
$id = 'unique-your-getPopularPosts';
$series = Yii::app()->cache->get($id);
if($series === false)
{
$series = Post::model()->getPopularPosts(5);
Yii::app()->cache->set($id, $series, 3600);
}
#3
Posted 27 December 2012 - 06:42 AM
#4
Posted 27 December 2012 - 09:38 AM
KonApaz, on 27 December 2012 - 05:13 AM, said:
check this
$id = 'unique-your-getPopularPosts';
$series = Yii::app()->cache->get($id);
if($series === false)
{
$series = Post::model()->getPopularPosts(5);
Yii::app()->cache->set($id, $series, 3600);
}Thanks, will give that a try!
I'm using CMemCache btw
Edit:
Did try it on this way, but it's the same story, on every reload the query is executed and saved in cache (it's never 'loaded' from the cache):
"Saving "serielist-popular" to cache"
Is there something wrong with my configuration?
'cache'=>array(
'class'=>'CMemCache',
'servers'=>array(
array(
'host'=>'localhost',
'port'=>11211
),
),
),
#6
Posted 27 December 2012 - 02:26 PM
softark, on 27 December 2012 - 10:12 AM, said:
Tried that, still the same result. I think it shouldn't matter, because the cache->set(); cache->get() method didn't work for me neither and that has actually nothing to do with the database itself (just the results got cached)
'db'=>array(
/* Secret stuff here */
'emulatePrepare' => true,
'charset' => 'utf8',
'enableProfiling' => false,
'queryCacheID' => 'cache'
),
#7
Posted 28 December 2012 - 04:52 AM
It might be worth trying the basic CFileCache instead for debugging.
And, I'm a bit afraid that you were misunderstanding something when you were interpreting the log. I mean, the cache might be working right. You would be better to make sure it *IS* failing.
$id = 'unique-your-getPopularPosts';
$series = Yii::app()->cache->get($id);
Yii::trace('read from cache : ' . ($series === false) ? 'false' : 'cached' );
if($series === false)
{
$series = Post::model()->getPopularPosts(5);
Yii::app()->cache->set($id, $series, 3600);
Yii::trace('write to cache');
}
#8
Posted 30 December 2012 - 02:50 PM
softark, on 28 December 2012 - 04:52 AM, said:
It might be worth trying the basic CFileCache instead for debugging.
And, I'm a bit afraid that you were misunderstanding something when you were interpreting the log. I mean, the cache might be working right. You would be better to make sure it *IS* failing.
$id = 'unique-your-getPopularPosts';
$series = Yii::app()->cache->get($id);
Yii::trace('read from cache : ' . ($series === false) ? 'false' : 'cached' );
if($series === false)
{
$series = Post::model()->getPopularPosts(5);
Yii::app()->cache->set($id, $series, 3600);
Yii::trace('write to cache');
}
Thanks! With CMemCache i get 'write to cache' every time in my trace log. With CFileCache instead, i get what i expect in my log, 'Serving "**NAME***" from cache' the second time i load my page, so that works as it should.
But i would like to use Memcache anyway, what can be the problem? A server side setting?
#9
Posted 30 December 2012 - 07:53 PM
Davey, on 30 December 2012 - 02:50 PM, said:
Yes, probably.
And if you are using PECL::memcached extension for interfacing with memcached, the doc says you have to set 'useMemcached' to true.
http://www.yiiframew...emcached-detail

Help














