Skip to content

Commit

Permalink
allow listeners to prevent caching
Browse files Browse the repository at this point in the history
  • Loading branch information
coastforge-fsc committed Jan 15, 2024
1 parent 58e6ffc commit ebc2a72
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Classes/Events/LoadLayersEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class LoadLayersEvent extends Event

private $layerService = null;

private $preventCaching = false;

/**
* @return array
*/
Expand Down Expand Up @@ -69,4 +71,14 @@ public function setAdditionalData(array $additionalData)
{
$this->additionalData = $additionalData;
}

public function isPreventCaching(): bool
{
return $this->preventCaching;
}

public function setPreventCaching(bool $preventCaching): void
{
$this->preventCaching = $preventCaching;
}
}
6 changes: 5 additions & 1 deletion src/Controller/LayerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class LayerController extends BaseController
* @var ContainerInterface
*/
protected $container = null;
private $preventCaching = false;

/**
* LayerController constructor.
Expand Down Expand Up @@ -70,7 +71,7 @@ public function layerAction(Request $request, $mapId, $lang)
$modifiedData['layer'][$key] = $this->addCustomLogic($layer, $lang);
}
$this->responseData = $modifiedData;
if (self::$useCache) {
if (self::$useCache && !$this->preventCaching) {
$this->storeDataInCache($request);
}
}
Expand All @@ -94,6 +95,9 @@ private function addCustomLogic($arrLayerData, $lang)
$event->setAdditionalData(["language" => $lang]);
$this->eventDispatcher->dispatch($event, $event::NAME);
$arrLayerData = $event->getLayerData();
if ($event->isPreventCaching()) {
$this->preventCaching = $event->isPreventCaching();
}
}
}
return $arrLayerData;
Expand Down

0 comments on commit ebc2a72

Please sign in to comment.