In Yii, I have enabled APC caching through the config/main.php file:
'cache' => array(
'class' => 'system.caching.CApcCache',
),
and it works just fine when I use Yii's built-in caching methods:
Yii::app()->cache->set('key', $value);
However, is there a way to temporarily turn this off based on configuration? I don't want to have it enabled while YII_DEBUG
is set to true, for example, and would like $votes = Yii::app()->cache->get("key");
to always return false as it does when it's empty.
I've tried turning this off by just commenting-out the configuration setting, but it gives (not unreasonable) errors: Call to a member function get() on a non-object
When you need to invalidate all the stored cache data, you can call yii\caching\Cache::flush(). You can flush the cache from the console by calling yii cache/flush as well. Info: Console application uses a separate configuration file by default.
You can register several cache application components. yii\caching\DbCache − Uses a database table to store cached data. Uou must create a table as specified in yii\caching\DbCache::$cacheTable. yii\caching\ApcCache − Uses PHP APC extension.
You could configure a cache class that does not cache at all (so it won't store anything and get()
will always return FALSE
).
Probably Yii already ships with a no-cache? Yes it does, it's called CDummyCache
and it does no caching at all.
It has been written for the problem you outline in your question that Yii::app()->cache
is NULL
.
See CachingDocs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With