huacnlee / rails-settings-cached

Global settings for your Rails application.
Other
1.06k stars 202 forks source link

Cache is read twice for a single value #255

Open RavWar opened 1 month ago

RavWar commented 1 month ago

Hi! I've noticed a slight performance issue using this gem and found out that by using standard Setting.app_name getters cache is hit twice and it takes twice as long to get the value. By using RailsSettings.config.cache_storage.fetch('rails-settings-cached')['app_name'] cache is hit once and the value returns twice as fast. This can be fixed by memoizing the return value of saved_value method here: https://github.com/huacnlee/rails-settings-cached/blob/main/lib/rails-settings/fields/base.rb#L36

Or is there a reason for this behavior? Thank you for your work, gem is great!