Sha256: 6e818393dcbea065ebb08da91067e1403d18935c08730c6e51ead867e549e233
Contents?: true
Size: 734 Bytes
Versions: 1
Compression:
Stored size: 734 Bytes
Contents
module RailsSettings class CachedSettings < Settings after_commit :rewrite_cache, on: %i(create update) def rewrite_cache Rails.cache.write("rails_settings_cached:#{var}", value) end after_commit :expire_cache, on: %i(destroy) def expire_cache Rails.cache.delete("rails_settings_cached:#{var}") end class << self def [](var_name) cache_key = "rails_settings_cached:#{var_name}" obj = Rails.cache.read(cache_key) obj = super(var_name) if obj.nil? return @@defaults[var_name.to_s] if obj.nil? obj end def save_default(key, value) return false unless send(key).nil? send("#{key}=", value) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails-settings-cached-0.4.2 | lib/rails-settings/cached_settings.rb |