Skip to content

Commit

Permalink
1015: Cleaned up cache handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Sep 25, 2024
1 parent ab02bc0 commit 5f8e03d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ SF1601_FORSENDELSES_TYPE_IDENTIFIKATOR=''
SF1601_TEST_MODE='true'

# Set to `-1 day`, say, to effectively disable cache.
# Run `bin/console tvist1:cache:clear` after changing this.
# Run `bin/console cache:pool:clear cache.app` after changing this.
SF1601_POST_FORESPOERG_CACHE_EXPIRE_AT='+1 day'

# Maximum attachment sizes for digital and physical post, respectively.
Expand Down
35 changes: 0 additions & 35 deletions src/Command/CacheClearCommand.php

This file was deleted.

15 changes: 11 additions & 4 deletions src/Service/SF1601/DigitalPoster.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use ItkDev\Serviceplatformen\Service\SF1601\SF1601;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;

Expand All @@ -22,22 +22,29 @@ class DigitalPoster

private array $options;

public function __construct(private CertificateLocatorHelper $certificateLocatorHelper, private MeMoHelper $meMoHelper, private readonly ForsendelseHelper $forsendelseHelper, private DigitalPostEnvelopeRepository $envelopeRepository, LoggerInterface $logger, array $options)
public function __construct(
private readonly CertificateLocatorHelper $certificateLocatorHelper,
private readonly MeMoHelper $meMoHelper,
private readonly ForsendelseHelper $forsendelseHelper,
private readonly DigitalPostEnvelopeRepository $envelopeRepository,
private readonly CacheInterface $cache,
LoggerInterface $logger,
array $options
)
{
$this->options = $this->resolveOptions($options);
$this->setLogger($logger);
}

public function canReceive(string $type, string $identifier): ?bool
{
$cache = new FilesystemAdapter();
$cacheKey = preg_replace(
'#[{}()/\\\\@:]+#',
'_',
implode('|||', [__METHOD__, $type, $identifier])
);

return $cache->get($cacheKey, function (ItemInterface $item) use ($type, $identifier): ?bool {
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($type, $identifier): ?bool {
try {
$service = $this->getSF1601();
$transactionId = Serializer::createUuid();
Expand Down

0 comments on commit 5f8e03d

Please sign in to comment.