eZ\Publish\Core\MVC\Symfony\Cache\Http\LocationAwareStore::purgeByRequest PHP Method

purgeByRequest() public method

If X-Location-Id or X-Group-Location-Id header is present, the store will purge cache for given locationId or group of locationIds. If not, regular purge by URI will occur.
public purgeByRequest ( Request $request ) : boolean
$request Symfony\Component\HttpFoundation\Request
return boolean True if purge was successful. False otherwise
    public function purgeByRequest(Request $request)
    {
        if (!$request->headers->has('X-Location-Id') && !$request->headers->has('X-Group-Location-Id')) {
            return $this->purge($request->getUri());
        }
        // Purge everything
        $locationId = $request->headers->get('X-Location-Id');
        if ($locationId === '*' || $locationId === '.*') {
            return $this->purgeAllContent();
        }
        // Usage of X-Group-Location-Id is deprecated.
        if ($request->headers->has('X-Group-Location-Id')) {
            $aLocationId = explode('; ', $request->headers->get('X-Group-Location-Id'));
        } elseif ($locationId[0] === '(' && substr($locationId, -1) === ')') {
            // Equivalent to X-Group-Location-Id, using a simple Regexp:
            // (123|456|789) => Purge for #123, #456 and #789 location IDs.
            $aLocationId = explode('|', substr($locationId, 1, -1));
        } else {
            $aLocationId = array($locationId);
        }
        if (empty($aLocationId)) {
            return false;
        }
        foreach ($aLocationId as $locationId) {
            $this->purgeLocation($locationId);
        }
        return true;
    }

Usage Example

 public function testPurgeAllContentByRequestBC()
 {
     $fs = $this->getFilesystemMock();
     $this->store->setFilesystem($fs);
     $locationCacheDir = $this->store->getLocationCacheDir();
     $staleCacheDir = str_replace(LocationAwareStore::LOCATION_CACHE_DIR, LocationAwareStore::LOCATION_STALE_CACHE_DIR, $locationCacheDir);
     $fs->expects($this->any())->method('exists')->with($locationCacheDir)->will($this->returnValue(true));
     $fs->expects($this->once())->method('mkdir')->with($staleCacheDir);
     $fs->expects($this->once())->method('mirror')->with($locationCacheDir, $staleCacheDir);
     $fs->expects($this->once())->method('remove')->with(array($staleCacheDir, $this->store->getLocationCacheLockName(), $locationCacheDir));
     $request = Request::create('/', 'PURGE');
     $request->headers->set('X-Location-Id', '*');
     $this->store->purgeByRequest($request);
 }