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;
|
||||
|
||||
$cache = Cache::getInstance();
|
||||
if($cache->enabled())
|
||||
{
|
||||
$tmp = '';
|
||||
if($cache->fetch('templates', $tmp)) {
|
||||
$templates = unserialize($tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
$templates = get_templates();
|
||||
$cache->set('templates', serialize($templates), 30);
|
||||
}
|
||||
}
|
||||
else
|
||||
$templates = get_templates();
|
||||
$templates = Cache::remember('templates', 5 * 60, function() {
|
||||
return get_templates();
|
||||
});
|
||||
|
||||
$options = '';
|
||||
foreach($templates as $key => $value)
|
||||
foreach($templates as $value)
|
||||
$options .= '<option ' . ($template_name == $value ? 'SELECTED' : '') . '>' . $value . '</option>';
|
||||
|
||||
global $twig;
|
||||
|
@ -138,29 +138,19 @@ if($twig_loader) {
|
||||
$twig_loader->prependPath(BASE . $template_path);
|
||||
}
|
||||
|
||||
function get_template_menus() {
|
||||
function get_template_menus(): array
|
||||
{
|
||||
global $template_name;
|
||||
|
||||
$cache = Cache::getInstance();
|
||||
if ($cache->enabled()) {
|
||||
$tmp = '';
|
||||
if ($cache->fetch('template_menus', $tmp)) {
|
||||
$result = unserialize($tmp);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($result)) {
|
||||
|
||||
$result = Cache::remember('template_menus', 10 * 60, function () use ($template_name) {
|
||||
$result = Menu::select(['name', 'link', 'blank', 'color', 'category'])
|
||||
->where('template', $template_name)
|
||||
->orderBy('category')
|
||||
->orderBy('ordering')
|
||||
->get();
|
||||
|
||||
if ($cache->enabled()) {
|
||||
$cache->set('template_menus', serialize($result->toArray()), 600);
|
||||
}
|
||||
}
|
||||
return $result->toArray();
|
||||
});
|
||||
|
||||
$menus = array();
|
||||
foreach($result as $menu) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user