-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start thinking to roll in more cache headers; however, shouldn't be n…
…ecessary.
- Loading branch information
1 parent
15b901b
commit 12ba90e
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Drupal\embargo\EventSubscriber; | ||
|
||
use Drupal\Core\Cache\RefinableCacheableDependencyInterface; | ||
use Drupal\search_api\Event\QueryPreExecuteEvent; | ||
use Drupal\search_api\Event\SearchApiEvents; | ||
use Drupal\search_api\Query\QueryInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* Views cache event subscriber implementation. | ||
*/ | ||
class ViewsCacheEventSubscriber implements EventSubscriberInterface { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function getSubscribedEvents() { | ||
return [ | ||
SearchApiEvents::QUERY_PRE_EXECUTE => 'preExecute', | ||
//'search_api.query_pre_execute.alter_cache_metadata' => ['alterCacheMetadata'], | ||
]; | ||
} | ||
|
||
public function preExecute(QueryPreExecuteEvent $event) { | ||
dsm($event->getQuery()->getTags()); | ||
if ($event->getQuery()->hasTag('alter_cache_metadata')) { | ||
$this->alterCacheMetadata($event); | ||
} | ||
|
||
$query = $event->getQuery(); | ||
if ($query instanceof RefinableCacheableDependencyInterface) { | ||
dsm($query->getCacheContexts()); | ||
dsm($query->getCacheTags()); | ||
dsm($query->getCacheMaxAge()); | ||
} | ||
} | ||
|
||
/** | ||
* Alter cache metadata. | ||
* | ||
* @param \Drupal\search_api\Event\QueryPreExecuteEvent $event | ||
* The pre-execution event. | ||
*/ | ||
public function alterCacheMetadata(QueryPreExecuteEvent $event) : void { | ||
$query = $event->getQuery(); | ||
if (!($query instanceof RefinableCacheableDependencyInterface)) { | ||
dsm('blah'); | ||
// Cannot add metadata to it. | ||
return; | ||
} | ||
if ($this->containsRelevantIndex($query)) { | ||
//$query->add | ||
} | ||
} | ||
|
||
protected function containsRelevantIndex(QueryInterface $query) : bool { | ||
dsm($query->getTags()); | ||
return FALSE; | ||
} | ||
|
||
} |