mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
Shorten code with Cache::remember
This commit is contained in:
parent
c52ca27126
commit
8e501c0e9c
@ -589,24 +589,12 @@ function template_form()
|
|||||||
{
|
{
|
||||||
global $template_name;
|
global $template_name;
|
||||||
|
|
||||||
$cache = Cache::getInstance();
|
$templates = Cache::remember('templates', 5 * 60, function() {
|
||||||
if($cache->enabled())
|
return get_templates();
|
||||||
{
|
});
|
||||||
$tmp = '';
|
|
||||||
if($cache->fetch('templates', $tmp)) {
|
|
||||||
$templates = unserialize($tmp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$templates = get_templates();
|
|
||||||
$cache->set('templates', serialize($templates), 30);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$templates = get_templates();
|
|
||||||
|
|
||||||
$options = '';
|
$options = '';
|
||||||
foreach($templates as $key => $value)
|
foreach($templates as $value)
|
||||||
$options .= '<option ' . ($template_name == $value ? 'SELECTED' : '') . '>' . $value . '</option>';
|
$options .= '<option ' . ($template_name == $value ? 'SELECTED' : '') . '>' . $value . '</option>';
|
||||||
|
|
||||||
global $twig;
|
global $twig;
|
||||||
|
@ -138,29 +138,19 @@ if($twig_loader) {
|
|||||||
$twig_loader->prependPath(BASE . $template_path);
|
$twig_loader->prependPath(BASE . $template_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_template_menus() {
|
function get_template_menus(): array
|
||||||
|
{
|
||||||
global $template_name;
|
global $template_name;
|
||||||
|
|
||||||
$cache = Cache::getInstance();
|
$result = Cache::remember('template_menus', 10 * 60, function () use ($template_name) {
|
||||||
if ($cache->enabled()) {
|
|
||||||
$tmp = '';
|
|
||||||
if ($cache->fetch('template_menus', $tmp)) {
|
|
||||||
$result = unserialize($tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($result)) {
|
|
||||||
|
|
||||||
$result = Menu::select(['name', 'link', 'blank', 'color', 'category'])
|
$result = Menu::select(['name', 'link', 'blank', 'color', 'category'])
|
||||||
->where('template', $template_name)
|
->where('template', $template_name)
|
||||||
->orderBy('category')
|
->orderBy('category')
|
||||||
->orderBy('ordering')
|
->orderBy('ordering')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
if ($cache->enabled()) {
|
return $result->toArray();
|
||||||
$cache->set('template_menus', serialize($result->toArray()), 600);
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$menus = array();
|
$menus = array();
|
||||||
foreach($result as $menu) {
|
foreach($result as $menu) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user