Skip to content

Commit

Permalink
- return correct configuration values regardless of cache status
Browse files Browse the repository at this point in the history
Fixes #1985
Fixes #1996
  • Loading branch information
jsqu99 authored and radar committed Sep 8, 2013
1 parent 6c1eea7 commit 6bce723
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
28 changes: 26 additions & 2 deletions core/app/models/spree/preferences/store.rb
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion core/spec/models/preferences/store_spec.rb
Expand Up @@ -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

0 comments on commit 6bce723

Please sign in to comment.