Пример #1
0
 private function executeSet($data, $time)
 {
     if ($this->isDisabled()) {
         return false;
     }
     if (!isset($this->key)) {
         return false;
     }
     $store['return'] = $data;
     $store['createdOn'] = time();
     if (isset($time)) {
         if ($time instanceof DateTime) {
             $expiration = intval($time->format('U'));
             $cacheTime = $expiration - $store['createdOn'];
         } else {
             $cacheTime = isset($time) && is_numeric($time) ? $time : self::$cacheTime;
         }
     } else {
         $cacheTime = self::$cacheTime;
     }
     $expiration = $store['createdOn'] + $cacheTime;
     if ($cacheTime > 0) {
         $expirationDiff = rand(0, floor($cacheTime * 0.15));
         $expiration -= $expirationDiff;
     }
     if ($this->stampedeRunning == true) {
         $spkey = $this->key;
         $spkey[0] = 'sp';
         // change "cache" data namespace to stampede namespace
         $this->driver->clear($spkey);
         $this->stampedeRunning = false;
     }
     return $this->driver->storeData($this->key, $store, $expiration);
 }
Пример #2
0
 /**
  * This clears out any locks that are present if this Item is prematurely destructed.
  */
 public function __destruct()
 {
     if (isset($this->stampedeRunning) && $this->stampedeRunning === true) {
         $spkey = $this->key;
         $spkey[0] = 'sp';
         $this->driver->clear($spkey);
     }
 }