Skip to content

Commit

Permalink
Tidied code inside preferences/store.rb
Browse files Browse the repository at this point in the history
* Methods always return nil in the absence of an explicit return.
* In-lined Preference retrieval and presence check.
* In-lined cache read presence check.

Fixes spree#2005
  • Loading branch information
parndt authored and radar committed Sep 24, 2012
1 parent 86e6b6e commit 7058e19
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions core/app/models/spree/preferences/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,23 @@ def exist?(key)
end

def get(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?
if (val = @cache.read(key)).present?
return val
end

return nil unless should_persist?

# if it's not in the cache, maybe it's in the database, but
# 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?

if preference = Spree::Preference.find_by_key(key)
# 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
preference.value
end
end

Expand Down

0 comments on commit 7058e19

Please sign in to comment.