Parent

Merb::Cache::GzipStore

Store that compresses cached data using GZip. Usually wraps other stores and good for caching of large pages.

Public Instance Methods

compress(data) click to toggle source
# File lib/merb-cache/stores/strategy/gzip_store.rb, line 47
def compress(data)
  return if data.nil?

  output = StringIO.new
  gz = Zlib::GzipWriter.new(output)
  gz.write(Marshal.dump(data))
  gz.close
  output.string
end
decompress(data) click to toggle source
# File lib/merb-cache/stores/strategy/gzip_store.rb, line 57
def decompress(data)
  return if data.nil?

  Marshal.load(Zlib::GzipReader.new(StringIO.new(data)).read)
end
delete(key, parameters = {}) click to toggle source
# File lib/merb-cache/stores/strategy/gzip_store.rb, line 39
def delete(key, parameters = {})
  @stores.map {|c| c.delete(key, parameters)}.any?
end
delete_all!() click to toggle source
# File lib/merb-cache/stores/strategy/gzip_store.rb, line 43
def delete_all!
  @stores.map {|c| c.delete_all! }.all?
end
exists?(key, parameters = {}) click to toggle source
# File lib/merb-cache/stores/strategy/gzip_store.rb, line 35
def exists?(key, parameters = {})
  @stores.capture_first {|c| c.exists?(key, parameters)}
end
fetch(key, parameters = {}, conditions = {}, &blk) click to toggle source
# File lib/merb-cache/stores/strategy/gzip_store.rb, line 30
def fetch(key, parameters = {}, conditions = {}, &blk)
  wrapper_blk = lambda { compress(blk.call) }
  read(key, parameters) || decompress(@stores.capture_first {|s| s.fetch(key, parameters, conditions, &wrapper_blk)})
end
read(key, parameters = {}) click to toggle source
# File lib/merb-cache/stores/strategy/gzip_store.rb, line 14
def read(key, parameters = {})
  decompress(@stores.capture_first {|c| c.read(key, parameters)})
end
writable?(key, parameters = {}, conditions = {}) click to toggle source
# File lib/merb-cache/stores/strategy/gzip_store.rb, line 10
def writable?(key, parameters = {}, conditions = {})
  @stores.any? {|c| c.writable?(key, parameters, conditions)}
end
write(key, data = nil, parameters = {}, conditions = {}) click to toggle source
# File lib/merb-cache/stores/strategy/gzip_store.rb, line 18
def write(key, data = nil, parameters = {}, conditions = {})
  if writable?(key, parameters, conditions)
    @stores.capture_first {|c| c.write(key, compress(data), parameters, conditions)}
  end
end
write_all(key, data = nil, parameters = {}, conditions = {}) click to toggle source
# File lib/merb-cache/stores/strategy/gzip_store.rb, line 24
def write_all(key, data = nil, parameters = {}, conditions = {})
  if writable?(key, parameters, conditions)
    @stores.map {|c| c.write_all(key, compress(data), parameters, conditions)}.all?
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.