Skip to content
Snippets Groups Projects
Commit e624ca46 authored by Kevin von Spiczak's avatar Kevin von Spiczak
Browse files

[WIP] switch to caching framework

parent 64234d7d
No related branches found
No related tags found
1 merge request!8Feature cw 428 caching framework
......@@ -29,6 +29,7 @@ namespace SGalinski\SgYoutube\Service;
use Exception;
use GuzzleHttp\Exception\ClientException;
use InvalidArgumentException;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Context\LanguageAspect;
......@@ -50,6 +51,18 @@ class YoutubeService {
public const API_PART_LOCALIZATIONS = 'localizations';
public const API_ORDER_BY = 'date';
/**
* @var FrontendInterface
*/
protected $cache;
/**
* @param FrontendInterface $cache
*/
public function __construct(FrontendInterface $cache) {
$this->cache = $cache;
}
/**
* Maps the json array from the YouTube call to return some unified value. The output from YouTube is pretty
* unsteady. Also we calculate the correct thumbnail sized and so on.
......@@ -317,7 +330,7 @@ class YoutubeService {
} catch (ClientException $exception) {
$jsonString = (string) $exception->getResponse()->getBody();
}
$jsonArray = ($jsonString !== '' ? json_decode($jsonString, TRUE) : []);
if ($jsonArray === NULL) {
throw new InvalidArgumentException(
......
......@@ -13,3 +13,10 @@ services:
SGalinski\SgYoutube\Service\YoutubeService:
public: true
autowire: false
arguments:
$cache: '@cache.sgyoutube_cache'
cache.sgyoutube_cache:
class: TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
factory: [ '@TYPO3\CMS\Core\Cache\CacheManager', 'getCache' ]
arguments: [ 'sgyoutube_cache' ]
......@@ -48,6 +48,8 @@ $iconRegistry->registerIcon(
['source' => 'EXT:sg_youtube/Resources/Public/Icons/youtube.svg']
);
// Caching
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['sgyoutube_cache'] ??= [];
// Hooks
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem']['sg_youtube']
= \SGalinski\SgYoutube\Hooks\PageLayoutView\PluginRenderer::class;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment