/** * @test */ public function readLockCanBeAcquiredTwice() { $lock1 = new Lock('testLock', false); $lock2 = new Lock('testLock', false); $this->assertTrue($lock1->release(), 'Lock 1 could not be released'); $this->assertTrue($lock2->release(), 'Lock 2 could not be released'); }
/** * Writes the cache data into the given cache file, using locking. * * @param string $cacheEntryPathAndFilename * @param string $data * @return boolean|integer Return value of file_put_contents */ protected function writeCacheFile($cacheEntryPathAndFilename, $data) { $lock = new Lock($cacheEntryPathAndFilename); $result = file_put_contents($cacheEntryPathAndFilename, $data); $lock->release(); return $result; }
/** * Internal get method, allows to nest locks by using the $acquireLock flag * * @param string $entryIdentifier * @param boolean $acquireLock * @return bool|string * @throws \InvalidArgumentException */ protected function internalGet($entryIdentifier, $acquireLock = true) { if ($entryIdentifier !== basename($entryIdentifier)) { throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073033); } $pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension; if ($this->frozen === true) { if ($acquireLock) { $lock = new Lock($pathAndFilename, false); } $result = isset($this->cacheEntryIdentifiers[$entryIdentifier]) ? file_get_contents($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension) : false; if ($acquireLock) { $lock->release(); } return $result; } if ($this->isCacheFileExpired($pathAndFilename, $acquireLock)) { return false; } if ($acquireLock) { $lock = new Lock($pathAndFilename, false); } $cacheData = file_get_contents($pathAndFilename); if ($acquireLock) { $lock->release(); } $dataSize = (int) substr($cacheData, -self::DATASIZE_DIGITS); return substr($cacheData, 0, $dataSize); }