Skip to content

Instantly share code, notes, and snippets.

@duncanbeevers
Created March 11, 2010 21:23
Show Gist options
  • Save duncanbeevers/329669 to your computer and use it in GitHub Desktop.
Save duncanbeevers/329669 to your computer and use it in GitHub Desktop.
class Memcached::CompressedRailsCache
def initialize(rails_cache)
@rails_cache = rails_cache
end
def get(key, raw = true) # raw is discarded
v = @rails_cache.get(key)
Marshal.load(Zlib::Inflate.inflate(v)) if v
end
def set(key, value, expiry = 0, raw = true) # raw is discarded
@rails_cache.set(
key,
Zlib::Deflate.deflate(Marshal.dump(value)),
expiry,
true)
end
def delete(key)
@rails_cache.delete(key)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment