Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function onAlter(LlmsResponseAlterEvent $event): void {
return;
}

$event->getCacheableMetadata()->addCacheContexts(['url.query_args.pagers:0']);

$current = $pager->getCurrentPage();
$total = $pager->getTotalPages();
$last = $total - 1;
Expand Down
2 changes: 2 additions & 0 deletions app/modules/platform/src/Llms/LlmsRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
$alter_event = new LlmsResponseAlterEvent($markdown, $request, $route_match);
$this->eventDispatcher->dispatch($alter_event);

$cacheable_metadata = $cacheable_metadata->merge($alter_event->getCacheableMetadata());

$response = new CacheableResponse($alter_event->getMarkdown(), 200, [
'Content-Type' => 'text/markdown; charset=UTF-8',
'X-Robots-Tag' => 'noindex',
Expand Down
16 changes: 15 additions & 1 deletion app/modules/platform/src/Llms/LlmsResponseAlterEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,31 @@

namespace Drupal\app_platform\Llms;

use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\EventDispatcher\Event;

final class LlmsResponseAlterEvent extends Event {

private CacheableMetadata $cacheableMetadata;

public function __construct(
private string $markdown,
public readonly Request $request,
public readonly RouteMatchInterface $routeMatch,
) {}
) {
$this->cacheableMetadata = new CacheableMetadata();
}

public function addCacheableDependency(CacheableDependencyInterface $dependency): void {
$this->cacheableMetadata = $this->cacheableMetadata->merge(CacheableMetadata::createFromObject($dependency));
}

public function getCacheableMetadata(): CacheableMetadata {
return $this->cacheableMetadata;
}

public function getMarkdown(): string {
return $this->markdown;
Expand Down
Loading