mongoid-app_settings
mongoid-app_settings copied to clipboard
Turning caching off
Is there any plan for an option to turn caching off, by any chance? :)
(I don't think this is an "Issue" but I couldn't figure out where else to ask it... github newbie as far as commenting/questioning goes...)
Алё, сыны, как дела?
Sorry, I completely missed this in my notification triage after holidays. I guess there could be such an option, but you should be careful what you wish for: if you refer to settings from multiple places in your request/response cycle, you'll get multiple calls to MongoDB. This could quickly cause performance issues.
If you'd still like this, let me know and I can add that and push a release.
could you reset cash, when user update field?
@makshark Yes, you can reset the cache by calling .reload
on the settings class you've defined. If you're using Rails, I recommend calling reload
in a before_action
so that each request starts with the latest settings loaded from MongoDB. There is an example in the README for this.
Hey guys, I didn't see any of these notifications, ha.
I did use the reload option in controllers; however, we also read these settings from non-controller parts of the app. What I actually did was ... what is the phrase ... monkey patch? ... and added a get() method (or re-defined it) which reloads and then returns the requested setting. It works. :)
module Mongoid
module AppSettings
module ClassMethods
def get setting
self.reload
if self.instance_values["settings"].include? setting then
self.send(setting)
else
raise "SettingDoesNotExist"
end
end
end
end
end
... but resetting the cache when it is updated, rather than always reloading when getting a value, seems like a better idea.
Under the context of distributed systems, one might want to always reload settings, or at least have a cache expiration