Skip to content

Instantly share code, notes, and snippets.

@LeifWarner
Created March 6, 2012 21:42
Show Gist options
  • Save LeifWarner/1989116 to your computer and use it in GitHub Desktop.
Save LeifWarner/1989116 to your computer and use it in GitHub Desktop.
require 'jruby-spymemcached'
class SpymemcachedWrapper
# Shamelessly cribbed from
# https://github.com/ikai/jruby-memcache-client/blob/master/lib/memcache.rb
def initialize(servers, opts)
@spymemcached = Spymemcached.new(servers)
at_exit { @spymemcached.shutdown }
@namespace = opts[:namespace] || opts["namespace"]
end
def get(key)
@spymemcached.get(make_cache_key(key))
end
def set(key, value, expiry = 0)
@spymemcached.set(make_cache_key(key), value, expiry)
end
protected
def make_cache_key(key)
if @namespace.nil? then
key
else
"#{@namespace}:#{key}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment