<?php
defined('_JEXEC') or die;
use Joomla\CMS\Cache\Cache;
use Joomla\CMS\Factory;
// Set the cache options.
$cache_group = '_footableghsvs';
$options = array(
'cachebase' => Factory::getApplication()->get('cache_path',
JPATH_SITE . '/cache'),
'lifetime' => 360,
'defaultgroup' => $cache_group,
'caching' => true
);
$cache = new Cache($options);
/* Create a safe ID for cached data in this case from URL parameters. Not always
clever. */
$cache_key = $cache->makeId();
if ($cache->contains($cache_key) && ($cacheGet = $cache->get($cache_key)))
{
$cacheGet = json_decode($cacheGet);
$rows = $cacheGet->rows;
$cols = $cacheGet->cols;
}
else
{
// Nothing in cache.
$cacheGet = false;
}
// Collect some data
if ($cacheGet === false)
{
$cols = $firstArrayWithWhatever;
$rows = $secondArrayWithWhatever;
// Cache the data for future use..
$cache->store(
json_encode(array('rows' => $rows, 'cols' => $cols)),
$cache_key,
$cache_group
);
}
// Do whatever you want with $rows and $cols.
libraries/src/Cache/ Joomla 4.0.5: https://github.com/joomla/joomla-cms/tree/4.0.5/libraries/src/Cache
libraries/src/Cache/Cache.php::makeId Joomla 4.0.5: https://github.com/joomla/joomla-cms/blob/4.0.5/libraries/src/Cache/Cache.php#L756-L802
libraries/src/Cache/Cache.php::__construct($options)Joomla 4.0.5: https://github.com/joomla/joomla-cms/blob/4.0.5/libraries/src/Cache/Cache.php#L43-L79
libraries/src/Cache/Cache.php::store()Joomla 4.0.5: https://github.com/joomla/joomla-cms/blob/4.0.5/libraries/src/Cache/Cache.php#L255-L278
libraries/src/Cache/Cache.php::get()Joomla 4.0.5: https://github.com/joomla/joomla-cms/blob/4.0.5/libraries/src/Cache/Cache.php#L215-L236