Built with ๐ and โ in San Francisco
A JRuby extension wraps the latest spymemcached client. Fastest jruby memcached client, threadsafe.
Start a local networked memcached server:
$ memcached -p 11211
Require the library and instantiate a Spymemcached object at a global level:
require 'spymemcached'
$cache = Spymemcached.new("localhost:11211")
Setup multiple servers with options
require 'spymemcached'
$cache = Spymemcached.new(['memcached1.host:11211', 'memcached2.host:11211', 'memcached3.host:11211'],
{:namespace => 'appName', :timeout => 0.1, :binary => true})
Valid +options+ are:
[:namespace] Prepends this value to all keys added or retrieved.
[:timeout] Time to use as the socket read timeout, seconds. Defaults to 0.5 sec.
[:binary] Talks binary protocol with Memcached server. Default to true.
[:should_optimize] If true, Spymemcached low-level optimization is in effect. Default to false.
Use spymemcached_store gem to integrate ActiveSupport cache store and spymemcached.jruby gem.
require 'spymemcached'
config.cache_store = :mem_cache_store, Spymemcached.new(servers, options).rails23
require 'spymemcached'
ActionController::Base.cache_store = :mem_cache_store, Spymemcached.new(servers, options).rails23
Spymemcached.jruby applies:
- Ketama key hash algorithm (see Spymemcached document or RJ's blog post for details)
- Gzip compressed when the cache data size is larger than 16kb.
- Binary protocol
Other default settings see Spymemcached DefaultConnectionFactory for details.
Benchmark result compared with gem dalli and jruby-memcached