Sha256: cabaf2a38fee313494ca8dbc3690546cf2512db36bffe21dfdba53fc4635b4bb
Contents?: true
Size: 883 Bytes
Versions: 1
Compression:
Stored size: 883 Bytes
Contents
module RailsSettings class CachedSettings < Settings def rewrite_cache Rails.cache.write(cache_key, value) end def expire_cache Rails.cache.delete(cache_key) end def cache_key self.class.cache_key(var, thing) end class << self def cache_key(var_name, scope_object) scope = "rails_settings_cached:" scope << "#{scope_object.class.base_class.to_s}-#{scope_object.id}:" if scope_object scope << "#{var_name}" end def [](var_name) value = Rails.cache.fetch(cache_key(var_name, @object)) do super(var_name) end if value.nil? @@defaults[var_name.to_s] if value.nil? else value end end def save_default(key, value) return false unless self[key].nil? self[key] = value end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails-settings-cached-0.4.5 | lib/rails-settings/cached_settings.rb |