Html cache revert

This commit is contained in:
Ernest Wiśniewski 2023-06-16 19:32:32 +02:00
parent d86b60a9f8
commit 452c587ca2
8 changed files with 20 additions and 32 deletions

View file

@ -4,7 +4,6 @@ namespace App\Twig\Components;
use App\Entity\Magazine;
use App\Repository\UserRepository;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
@ -19,6 +18,7 @@ final class ActiveUsersComponent
public function __construct(
private readonly UserRepository $userRepository,
private readonly CacheInterface $cache,
private readonly Environment $twig,
private readonly RequestStack $requestStack
) {
@ -26,9 +26,7 @@ final class ActiveUsersComponent
public function getHtml(ComponentAttributes $attributes): string
{
$cache = new FilesystemAdapter();
return $cache->get(
return $this->cache->get(
"active_users_{$this->magazine?->getId()}_{$this->requestStack->getCurrentRequest()?->getLocale()}",
function (ItemInterface $item) {
$item->expiresAfter(60);

View file

@ -5,8 +5,8 @@ namespace App\Twig\Components;
use App\Controller\User\ThemeSettingsController;
use App\Entity\EntryComment;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Cache\Adapter\FilesystemTagAwareAdapter;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use Symfony\UX\TwigComponent\ComponentAttributes;
@ -22,6 +22,7 @@ final class EntryCommentsNestedComponent
public function __construct(
private readonly Environment $twig,
private readonly Security $security,
private readonly CacheInterface $cache,
private readonly RequestStack $requestStack
) {
}
@ -31,9 +32,7 @@ final class EntryCommentsNestedComponent
$commentId = $this->comment->root?->getId() ?? $this->comment->getId();
$userId = $this->security->getUser()?->getId();
$cache = new FilesystemTagAwareAdapter();
return $cache->get(
return $this->cache->get(
"entry_comments_nested_{$commentId}_{$userId}_{$this->view}_{$this->requestStack->getCurrentRequest()?->getLocale()}",
function (ItemInterface $item) use ($commentId, $userId) {
$item->expiresAfter(3600);

View file

@ -5,8 +5,8 @@ namespace App\Twig\Components;
use App\Controller\User\ThemeSettingsController;
use App\Entity\PostComment;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Cache\Adapter\FilesystemTagAwareAdapter;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use Symfony\UX\TwigComponent\ComponentAttributes;
@ -22,6 +22,7 @@ final class PostCommentsNestedComponent
public function __construct(
private readonly Environment $twig,
private readonly Security $security,
private readonly CacheInterface $cache,
private readonly RequestStack $requestStack
) {
}
@ -33,9 +34,7 @@ final class PostCommentsNestedComponent
$postId = $comment->post->getId();
$userId = $this->security->getUser()?->getId();
$cache = new FilesystemTagAwareAdapter();
return $cache->get(
return $this->cache->get(
"post_comments_nested_{$commentId}_{$userId}_{$this->view}_{$this->requestStack->getCurrentRequest()?->getLocale()}",
function (ItemInterface $item) use ($commentId, $userId, $postId) {
$item->expiresAfter(3600);

View file

@ -4,8 +4,8 @@ namespace App\Twig\Components;
use App\Entity\Post;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Cache\Adapter\FilesystemTagAwareAdapter;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use Symfony\UX\TwigComponent\ComponentAttributes;
@ -19,6 +19,7 @@ final class PostCommentsPreviewComponent
public function __construct(
private readonly Environment $twig,
private readonly Security $security,
private readonly CacheInterface $cache,
private readonly RequestStack $requestStack
) {
}
@ -28,9 +29,7 @@ final class PostCommentsPreviewComponent
$postId = $this->post->getId();
$userId = $this->security->getUser()?->getId();
$cache = new FilesystemTagAwareAdapter();
return $cache->get(
return $this->cache->get(
"post_comment_preview_{$postId}_{$userId}_{$this->requestStack->getCurrentRequest()?->getLocale()}",
function (ItemInterface $item) use ($postId, $userId, $attributes) {
$item->expiresAfter(3600);

View file

@ -5,7 +5,6 @@ namespace App\Twig\Components;
use App\Entity\Entry;
use App\Repository\EntryRepository;
use App\Twig\Runtime\UserExtensionRuntime;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
@ -30,6 +29,7 @@ final class RelatedEntriesComponent
public function __construct(
private readonly EntryRepository $repository,
private readonly CacheInterface $cache,
private readonly Environment $twig,
private readonly RequestStack $requestStack
) {
@ -56,9 +56,7 @@ final class RelatedEntriesComponent
$entryId = $this->entry?->getId();
$magazine = str_replace('@', '', $this->magazine);
$cache = new FilesystemAdapter();
return $cache->get(
return $this->cache->get(
"related_entries_{$magazine}_{$this->tag}_{$entryId}_{$this->type}_{$this->requestStack->getCurrentRequest()?->getLocale()}",
function (ItemInterface $item) use ($attributes) {
$item->expiresAfter(60);

View file

@ -3,7 +3,6 @@
namespace App\Twig\Components;
use App\Repository\MagazineRepository;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
@ -27,6 +26,7 @@ final class RelatedMagazinesComponent
public function __construct(
private readonly MagazineRepository $repository,
private readonly CacheInterface $cache,
private readonly Environment $twig,
private readonly RequestStack $requestStack
) {
@ -52,9 +52,7 @@ final class RelatedMagazinesComponent
{
$magazine = str_replace('@', '', $this->magazine);
$cache = new FilesystemAdapter();
return $cache->get(
return $this->cache->get(
"related_magazines_{$magazine}_{$this->tag}_{$this->type}_{$this->requestStack->getCurrentRequest()?->getLocale()}",
function (ItemInterface $item) use ($attributes, $magazine) {
$item->expiresAfter(60);

View file

@ -5,7 +5,6 @@ namespace App\Twig\Components;
use App\Entity\Post;
use App\Repository\PostRepository;
use App\Twig\Runtime\UserExtensionRuntime;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
@ -30,6 +29,7 @@ final class RelatedPostsComponent
public function __construct(
private readonly PostRepository $repository,
private readonly CacheInterface $cache,
private readonly Environment $twig,
private readonly RequestStack $requestStack
) {
@ -56,9 +56,7 @@ final class RelatedPostsComponent
$postId = $this->post?->getId();
$magazine = str_replace('@', '', $this->magazine);
$cache = new FilesystemAdapter();
return $cache->get(
return $this->cache->get(
"related_posts_{$magazine}_{$this->tag}_{$postId}_{$this->type}_{$this->requestStack->getCurrentRequest()?->getLocale()}",
function (ItemInterface $item) use ($attributes) {
$item->expiresAfter(60);

View file

@ -6,7 +6,7 @@ use App\Entity\Contracts\VotableInterface;
use App\Service\CacheService;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use Symfony\UX\TwigComponent\ComponentAttributes;
@ -20,15 +20,14 @@ final class VotersInlineComponent
public function __construct(
private readonly Environment $twig,
private readonly CacheInterface $cache,
private readonly CacheService $cacheService,
) {
}
public function getHtml(ComponentAttributes $attributes): string
{
$cache = new FilesystemAdapter();
return $cache->get(
return $this->cache->get(
$this->cacheService->getVotersCacheKey($this->subject),
function (ItemInterface $item) use ($attributes) {
$item->expiresAfter(3600);