Esempio n. 1
0
 /**
  * Caching setter
  * @param string $field caching field name
  * @param mixed $Value caching value
  * @param int $type value type
  * @param int $expiration expiration timestamp
  * @param int $tries set tries count
  */
 public function set($field, $Value, $type = Item::TYPE_STRING, $expiration = 0, $tries = self::TRIES_SET)
 {
     if ($tries > 0) {
         $this->load(true, true);
         $Item = new Item($field, $type);
         $Item->setValue($Value)->setExpiration($expiration);
         self::$Value->setValue($Item);
         try {
             $this->save(true);
         } catch (CasErrorException $Ex) {
             usleep(mt_rand(self::TIMEOUT_CAS_MINIMUM, self::TIMEOUT_CAS_MAXIMUM));
             $this->set($field, $Value, $type, $expiration, $tries - 1);
         }
     } else {
         throw new CasErrorException('could not set value to cache');
     }
 }