I've been searching for answers to some questions I have on APC Caching specifically related to CActiveRecord but was unable to find anything that really helped. What I found seemed murky, and there are a number of unanswered cries for help in this forum regarding this subject. Therefore I thought that it might be time to start up some discussions and clarify the mysteries.
What initiated my quest was my desire to do some query caching. I wanted to use APC, as all-around, it seemed to have the claims of best performance (when configured correctly). It looked straightforward enough at the start and I really didn't have much trouble installing it on my VM (VirtualBox with Ubuntu 12.04). But then I became confused when I used the cache() method for a findAll query: the results were cached with no problem and they were retrieved with no problem, but then I got into using the dependency with no luck. Finally frustrated, I decided I would handle the caching myself using CApcCache's get and set. Lo and behold, the query continued to be cached even though I removed the cache() method! So if I may, I would like to start the discussion with this:
This resulted in findAll getting cached by default, unless I added cached(0) to disable it. But I didn't want to do that throughout the rest of the code as that would return stale data where it shouldn't. I couldn't find documentation as to why this was happening, then realized that is likely setting it as the default for the system. So I did this:
Voila! No more default caching and I could set and get what I wanted. I want to do more with this, however, perhaps some settings where some models will cache as the data may not change for long periods of time, but am a little stumped on how to progress. I was trying to override the cache() to use CApcCache and was only able to save to the cache and not serve from it.
I would love some input and I will add as much as I have figured out thus far and figure out as I work through my project.
Thanks in advance!
What initiated my quest was my desire to do some query caching. I wanted to use APC, as all-around, it seemed to have the claims of best performance (when configured correctly). It looked straightforward enough at the start and I really didn't have much trouble installing it on my VM (VirtualBox with Ubuntu 12.04). But then I became confused when I used the cache() method for a findAll query: the results were cached with no problem and they were retrieved with no problem, but then I got into using the dependency with no luck. Finally frustrated, I decided I would handle the caching myself using CApcCache's get and set. Lo and behold, the query continued to be cached even though I removed the cache() method! So if I may, I would like to start the discussion with this:
'components'=>array(
...
'cache'=>array(
'class'=>'CApcCache',
),
This resulted in findAll getting cached by default, unless I added cached(0) to disable it. But I didn't want to do that throughout the rest of the code as that would return stale data where it shouldn't. I couldn't find documentation as to why this was happening, then realized that is likely setting it as the default for the system. So I did this:
'components'=>array(
...
'apcCache'=>array(
'class'=>'CApcCache',
),
Voila! No more default caching and I could set and get what I wanted. I want to do more with this, however, perhaps some settings where some models will cache as the data may not change for long periods of time, but am a little stumped on how to progress. I was trying to override the cache() to use CApcCache and was only able to save to the cache and not serve from it.
I would love some input and I will add as much as I have figured out thus far and figure out as I work through my project.
Thanks in advance!