Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- return correct configuration values regardless of cache status

Fixes #1985
Fixes #1996
  • Loading branch information...
commit 6bce723114dc11fc20e1ac4f64ff32c3748888d6 1 parent 6c1eea7
@jsqu99 jsqu99 authored radar committed
View
28 core/app/models/spree/preferences/store.rb
@@ -23,11 +23,35 @@ def set(key, value, type)
end
def exist?(key)
- @cache.exist? key
+ @cache.exist?(key) || Spree::Preference.where(:key => key).exists?
end
def get(key)
- @cache.read(key)
+ # look first in our cache
+ val = @cache.read(key)
+
+ # return the retrieved value, if it's in the cache
+ return val if val.present?
+
+ return nil unless should_persist?
+
+ # if it's not in the cache, maybe it's in the database, but
+ # has been cleared from the cache
+
+ # does it exist in the database?
+ preference = Spree::Preference.find_by_key(key)
+
+ if preference.present?
+
+ # it does exist, so let's put it back into the cache
+ @cache.write(preference.key, preference.value)
+
+ # and return the value
+ return preference.value
+ else
+ # it never existed and our initial cache miss was correct
+ return nil
+ end
end
def delete(key)
View
8 core/spec/models/preferences/store_spec.rb
@@ -15,4 +15,10 @@
@store.set :test, false, :boolean
@store.get(:test).should be_false
end
-end
+
+ it "returns the correct preference value when the cache is empty" do
+ @store.set :test, "1", :string
+ Rails.cache.clear
+ @store.get(:test).should == "1"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.