protected function uncacheClassName($className, $indexKey, $intKey) { $cache = Cache::me(); $pool = SemaphorePool::me(); if ($pool->get($intKey)) { $indexList = $cache->mark($className)->get($indexKey); $cache->mark($className)->delete($indexKey); if ($indexList) { foreach (array_keys($indexList) as $key) { $cache->mark($className)->delete($key); } } $pool->free($intKey); return true; } $cache->mark($className)->delete($indexKey); return false; }
private function operate($path, $value = null, $expires = null) { $key = hexdec(substr(md5($path), 3, 2)) + 1; $pool = SemaphorePool::me(); if (!$pool->get($key)) { return null; } try { $old = umask(077); $fp = fopen($path, $value !== null ? 'wb' : 'rb'); umask($old); } catch (BaseException $e) { $pool->drop($key); return null; } if ($value !== null) { fwrite($fp, $this->prepareData($value)); fclose($fp); if ($expires < parent::TIME_SWITCH) { $expires += time(); } try { touch($path, $expires); } catch (BaseException $e) { // race-removed } return $pool->drop($key); } else { if (($size = filesize($path)) > 0) { $data = fread($fp, $size); } else { $data = null; } fclose($fp); $pool->drop($key); return $data ? $this->restoreData($data) : null; } }
private function checkMap($objectKey) { $pool = SemaphorePool::me(); $semKey = $this->keyToInt($this->indexKey); if (!$pool->get($semKey)) { return false; } if (!($map = Cache::me()->mark($this->className)->get($this->indexKey))) { $pool->free($semKey); return false; } if (!isset($map[$objectKey])) { $pool->free($semKey); return false; } $pool->free($semKey); return true; }
public function __construct($segmentId) { parent::__construct($segmentId); $this->locker = SemaphorePool::me(); }