mirror of
https://github.com/SkillDisplay/TYPO3ContentElements.git
synced 2024-11-22 03:16:10 +01:00
[FEATURE] Add optional caching for skill set data retrieval
This commit is contained in:
parent
80dcd33175
commit
15ddcb4158
5 changed files with 49 additions and 5 deletions
|
@ -25,6 +25,8 @@ namespace SkillDisplay\SkilldisplayContent\Frontend\DataProcessing;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use SkillDisplay\PHPToolKit\Api\SkillSet;
|
use SkillDisplay\PHPToolKit\Api\SkillSet;
|
||||||
|
use TYPO3\CMS\Core\Cache\CacheManager;
|
||||||
|
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||||
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
|
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
|
||||||
|
@ -45,14 +47,36 @@ class SkillSets implements DataProcessorInterface
|
||||||
array $processorConfiguration,
|
array $processorConfiguration,
|
||||||
array $processedData
|
array $processedData
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$as = $cObj->stdWrapValue('as', $processorConfiguration, 'skillSets');
|
$as = $cObj->stdWrapValue('as', $processorConfiguration, 'skillSets');
|
||||||
|
$skillSetsIdsRaw = (string)$cObj->stdWrapValue('skillSets', $processorConfiguration);
|
||||||
$skillSetIds = GeneralUtility::intExplode(
|
$skillSetIds = GeneralUtility::intExplode(
|
||||||
',',
|
',',
|
||||||
(string)$cObj->stdWrapValue('skillSets', $processorConfiguration),
|
$skillSetsIdsRaw,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
$skillSets = [];
|
|
||||||
|
|
||||||
|
$enableCache = $processorConfiguration['cache'] ?? false;
|
||||||
|
if ($enableCache) {
|
||||||
|
$cacheKey = md5($skillSetsIdsRaw) . $as;
|
||||||
|
/** @var VariableFrontend $cache */
|
||||||
|
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('sdcontent');
|
||||||
|
if ($cache->has($cacheKey)) {
|
||||||
|
$data = $cache->get($cacheKey);
|
||||||
|
} else {
|
||||||
|
$data = $this->generateData($skillSetIds);
|
||||||
|
$cache->set($cacheKey, $data);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$data = $this->generateData($skillSetIds);
|
||||||
|
}
|
||||||
|
$processedData[$as] = $data;
|
||||||
|
return $processedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function generateData(array $skillSetIds): array
|
||||||
|
{
|
||||||
|
$skillSets = [];
|
||||||
foreach ($skillSetIds as $skillSetId) {
|
foreach ($skillSetIds as $skillSetId) {
|
||||||
try {
|
try {
|
||||||
$skillSets[] = $this->skillSetApi->getById($skillSetId, true);
|
$skillSets[] = $this->skillSetApi->getById($skillSetId, true);
|
||||||
|
@ -60,8 +84,6 @@ class SkillSets implements DataProcessorInterface
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $skillSets;
|
||||||
$processedData[$as] = $skillSets;
|
|
||||||
return $processedData;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
Configuration/TypoScript/constants.typoscript
Normal file
1
Configuration/TypoScript/constants.typoscript
Normal file
|
@ -0,0 +1 @@
|
||||||
|
SkilldisplayContent.skillSet.cache = 0
|
|
@ -17,6 +17,7 @@ tt_content.skilldisplay_skillset {
|
||||||
dataProcessing {
|
dataProcessing {
|
||||||
10 = SkillDisplay\SkilldisplayContent\Frontend\DataProcessing\SkillSets
|
10 = SkillDisplay\SkilldisplayContent\Frontend\DataProcessing\SkillSets
|
||||||
10 {
|
10 {
|
||||||
|
cache = {$SkilldisplayContent.skillSet.cache}
|
||||||
skillSets.field = skilldisplay_skillset
|
skillSets.field = skilldisplay_skillset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,10 @@ Or copy the files from `/Resources/Private/Templates/ContentElements/` to your e
|
||||||
Configuration
|
Configuration
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
It is possible to cache the API results for Skill Sets with this TypoScript constant::
|
||||||
|
|
||||||
|
SkilldisplayContent.skillSet.cache = 1
|
||||||
|
|
||||||
You may include default CSS for the templates in your TypoScript::
|
You may include default CSS for the templates in your TypoScript::
|
||||||
|
|
||||||
page.includeCSS.skilldisplay = EXT:skilldisplay_content/Resources/Public/Css/Styles.css
|
page.includeCSS.skilldisplay = EXT:skilldisplay_content/Resources/Public/Css/Styles.css
|
||||||
|
|
|
@ -25,4 +25,20 @@
|
||||||
// todo v11?
|
// todo v11?
|
||||||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'][$extKey] =
|
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'][$extKey] =
|
||||||
\SkillDisplay\SkilldisplayContent\Backend\Preview::class;
|
\SkillDisplay\SkilldisplayContent\Backend\Preview::class;
|
||||||
|
|
||||||
|
|
||||||
|
$caches = [
|
||||||
|
'sdcontent',
|
||||||
|
];
|
||||||
|
foreach ($caches as $cacheName) {
|
||||||
|
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$cacheName] = [
|
||||||
|
'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
|
||||||
|
'backend' => \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend::class,
|
||||||
|
'options' => [
|
||||||
|
'defaultLifetime' => 2592000, // 30 days
|
||||||
|
],
|
||||||
|
'groups' => ['lowlevel']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
})('skilldisplay_content');
|
})('skilldisplay_content');
|
||||||
|
|
Loading…
Reference in a new issue