outl1ne / nova-settings

A Laravel Nova tool for editing custom settings using native Nova fields.
MIT License
274 stars 97 forks source link

Availability to cache settings #130

Closed romainvausetrustup closed 2 years ago

romainvausetrustup commented 2 years ago

Hi there !

Thanks for the nice work of this package,

Would it be possible to have a cache feature for the settings ? In my case I have a settings that's loaded on every pages but is a data that will not change that often.

I was thinking in the helpers.php to have a method params that will be the cache duration or something ?

if (!function_exists('nova_get_setting')) {
    function nova_get_setting($settingKey, $default = null)
    {
        return NovaSettings::getSetting($settingKey, $default);
    }
}

Thank you !

Tarpsvo commented 2 years ago

Hi! You can create your own wrapping helper.

function get_cached_setting($key, $default) {
  return Cache::remember($key, fn() => nova_get_setting($key, $default));
}