Browse files

[merb-cache] Decompress only once in Merb::Cache::GzipStore#fetch

* This change misses specs mainly because the current
  merb-cache specs seem rather horrible and I couldn't
  find an easy way to spec it (The other specs use an
  ugly mix of mocking/stubbing and are pretty inconsistent
  imho. They could definitely need some refactoring!

* Fixed formatting weirdness in abstract_strategy_store.rb

[#1013 state:resolved]
  • Loading branch information...
1 parent e2e3866 commit 923406abf993b4e82938a342c506dff1e0abcad5 @snusnu snusnu committed Oct 22, 2009
View
32 merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb
@@ -35,29 +35,29 @@ module Merb::Cache
class AbstractStrategyStore < AbstractStore
# START: interface for creating strategy stores. This should/might change.
def self.contextualize(*stores)
- Class.new(self) do
- cattr_accessor :contextualized_stores
+ Class.new(self) do
+ cattr_accessor :contextualized_stores
- self.contextualized_stores = stores
- end
+ self.contextualized_stores = stores
end
+ end
- class << self
- alias_method :[], :contextualize
- end
+ class << self
+ alias_method :[], :contextualize
+ end
- attr_accessor :stores
+ attr_accessor :stores
- def initialize(config = {})
- @stores = contextualized_stores.map do |cs|
- case cs
- when Symbol
- Merb::Cache[cs]
- when Class
- cs.new(config)
- end
+ def initialize(config = {})
+ @stores = contextualized_stores.map do |cs|
+ case cs
+ when Symbol
+ Merb::Cache[cs]
+ when Class
+ cs.new(config)
end
end
+ end
# END: interface for creating strategy stores.
View
2 merb-cache/lib/merb-cache/stores/strategy/gzip_store.rb
@@ -29,7 +29,7 @@ def write_all(key, data = nil, parameters = {}, conditions = {})
def fetch(key, parameters = {}, conditions = {}, &blk)
wrapper_blk = lambda { compress(blk.call) }
- decompress(read(key, parameters) || @stores.capture_first {|s| s.fetch(key, parameters, conditions, &wrapper_blk)})
+ read(key, parameters) || decompress(@stores.capture_first {|s| s.fetch(key, parameters, conditions, &wrapper_blk)})
end
def exists?(key, parameters = {})

0 comments on commit 923406a

Please sign in to comment.