Created
May 30, 2013 17:51
-
-
Save maccman/5679726 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dalli' | |
require 'memcachier' | |
module Sprockets | |
module Cache | |
# A simple Memcache cache store. | |
# | |
# environment.cache = Sprockets::Cache::MemcacheStore.new | |
# | |
class MemcacheStore | |
def initialize(key_prefix = 'sprockets') | |
@memcache = Dalli::Client.new | |
@key_prefix = key_prefix | |
Dalli.logger = Logger.new('/dev/null') | |
end | |
# Lookup value in cache | |
def [](key) | |
data = @memcache.get path_for(key) | |
Marshal.load data if data | |
end | |
# Save value to cache | |
def []=(key, value) | |
@memcache.set path_for(key), Marshal.dump(value) | |
value | |
end | |
private | |
def path_for(key) | |
"#{@key_prefix}:#{key}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment