Skip to content

Commit

Permalink
added doctrine/cache 2.1 and adjusted InstagramClient.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Mette committed Aug 14, 2023
1 parent f7f4eb4 commit 25a5b10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"contao/news-bundle": "^4.4",
"nickdnk/graph-sdk": "^6.0 || ^7.0",
"abraham/twitteroauth": "~1.1 || ~2.0",
"guzzlehttp/guzzle": "~6.0",
"guzzlehttp/guzzle": "^6.3",
"kevinrob/guzzle-cache-middleware": "^3.2",
"doctrine/cache": "^2.1",
"doctrine/dbal": "^2.0 || ^3.0",
Expand Down
17 changes: 15 additions & 2 deletions src/Importer/InstagramClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use Contao\File;
use Contao\FilesModel;
use Contao\StringUtil;
use Doctrine\Common\Cache\FilesystemCache;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
Expand All @@ -34,6 +34,7 @@
use Kevinrob\GuzzleCache\Storage\DoctrineCacheStorage;
use Kevinrob\GuzzleCache\Strategy\GreedyCacheStrategy;
use Psr\Log\LoggerInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

class InstagramClient
{
Expand Down Expand Up @@ -299,7 +300,19 @@ private function getCachedClient(int $moduleId = null): Client

if (!isset($clients[$key])) {
$stack = HandlerStack::create();
$stack->push(new CacheMiddleware(new GreedyCacheStrategy(new DoctrineCacheStorage(new FilesystemCache($this->cache->getCacheDir($moduleId))), $this->cache->getCacheTtl())), 'cache');

$cachePool = new FilesystemAdapter('',0, $this->cache->getCacheDir($moduleId));
$cache = DoctrineProvider::wrap($cachePool);

$stack->push(
new CacheMiddleware(
new GreedyCacheStrategy(
new DoctrineCacheStorage(
$cache
),
$this->cache->getCacheTtl()
)
), 'cache');

$clients[$key] = (new Client(['handler' => $stack]));
}
Expand Down

0 comments on commit 25a5b10

Please sign in to comment.