salex772
(Salex772)
September 11, 2013, 7:44pm
1
Hi everybody,
I need to cache some heavy function result, which returns true or false.
$bool_var = Yii::app()->cache->get($cache_id);
if ($bool_var === false) {
$bool_var = VeryHeavyFunction_Which_May_Return_false;
Yii::app()->cache->set($cache_id, $bool_var, 60);
}
In my case, $bool_var may be ‘false’ by function result, this does not mean that cache in not valid. Is there any way to validate cache values without ‘=== false’. Smth like IscacheValid()
konapaz
(Konapaz)
September 11, 2013, 10:15pm
2
Hi
I understood the problem
You could make this trick
//1) create a simple empty class MyFalseClass
$bool_var = Yii::app()->cache->get($cache_id);
if ($bool_var === false) {
$bool_var = VeryHeavyFunction_Which_May_Return_false;
if ($bool_var === false) $bool_var = new MyFalseClass()
Yii::app()->cache->set($cache_id, $bool_var, 60);
}
//now, retrieve the real false
if ($bool_var instanceof MyFalseClass) $bool_var = false;