Yii Framework Forum: Cache Boolean Values - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cache Boolean Values How to deal with variables than can be false or true Rate Topic: -----

#1 User is offline   Alex Shwarc 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 08-September 13
  • Location:Russia, Moscow

Posted 11 September 2013 - 02:44 PM

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() ???
0

#2 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,361
  • Joined: 21-February 11
  • Location:Greece

Posted 11 September 2013 - 05:15 PM

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;

Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
1

#3 User is offline   Alex Shwarc 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 08-September 13
  • Location:Russia, Moscow

Posted 13 September 2013 - 08:29 AM

Thanx!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users