huacnlee / rails-settings-cached

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

Read from DB directly #60

Closed adis-io closed 6 years ago

adis-io commented 9 years ago

For example, I want to read key from DB directly, not from cache. Is it possible?

huacnlee commented 9 years ago

Why? What difference?

adis-io commented 9 years ago

I use two rails apps in one machine. They have shared classes, models and etc through rails engine. So when I change values from one app changes not visible in other app. It would be good if I can fetch values from DB something like that: Setting.mykey!

mrj commented 9 years ago

The exclamation mark variant is a good idea.

Another reason to bypass the cache is when you want to lock a setting when reading it (SELECT...FOR UPDATE) to control exclusive access to a resource.

MichaelSp commented 9 years ago

Same here. Value changes in the DB sometimes without the rails app noticing. So I need a way to invalidate the cache or reload directly.

mlensment commented 9 years ago

Second that.

nykma commented 8 years ago

+1 for this.

prashantham commented 8 years ago

+1. Is there any other way to reload setting?

jpbullalayao commented 8 years ago

Would love to load directly from DB as well

idl3 commented 8 years ago

We can mark the settings (key/global) as stale and retrieve the new one for caching if we still want the performance gains. Much like a timestamp for last updated?

brateq commented 7 years ago

Same problem here, but on Elastic Beanstalk from Amazon. After update in form, rest of the app (like workers) doesn't know about change and still uses cached variable. How can I force to reload cached settings?

kabasakalis commented 7 years ago

For object scoped settings, I found that this works:

@page = Page.find(params[:id])

@page.settings.unscoped.find_by(var: :setting_id, thing_id: @page.id, thing_type: 'Page')
erbunao commented 4 years ago

I was wondering why was this closed? Was there a resolution/workaround to force reload?

huacnlee commented 4 years ago

https://github.com/ruby-china/homeland/blob/master/app/controllers/admin/site_configs_controller.rb#L24

erbunao commented 4 years ago

https://github.com/ruby-china/homeland/blob/master/app/controllers/admin/site_configs_controller.rb#L24

@huacnlee Apologies for not getting what the line means. Could you elaborate a bit?

huacnlee commented 4 years ago
2.6.3 :002 > Setting.all
 => #<ActiveRecord::Relation [...]>
2.6.3 :002 > Setting.find_by(var: "setting_id")