gem install memcache-client
config/environments
# For CachedModel
#require 'rubygems'
# In production.rb
require 'cached_model'
memcache_options = {
:c_threshold => 10_000,
:compression => true,
:debug => true,
:namespace => 'ning',
:readonly => false,
:urlencode => false
}
CACHE = MemCache.new memcache_options
# These are the IP addresses and ports of the memcached servers
CACHE.servers = ['*.*.*.*:11211', '*.*.*.*:11211']#
另一篇
Ruby MemCache Client 使用说明
第一步请到
http://www.deveiate.org/projects/RMemCache/wiki下载Ruby-MemCache-0.0.4.gem ,这个需要io-reactor支持。如果你使用Windows,安装的是ruby 1.8.2 (2004-12-25) [i386-mswin32],那么请使用以下命令远程安装,因为这个版本不能使用Ruby-MemCahce 0.0.4版。
gem install Ruby-MemCache --remote
使用以下语句即可将你需要存储Object(因为Ruby中一切者为Object)到MemCache中:
require 'rubygems'
require_gem 'Ruby-MemCache'
#ruquire 'memcache'
cache = MemCache::new '192.168.0.31:11211',
# '10.0.0.17:11211:3', # weighted
:debug => true,
:c_threshold => 100_000,
:compression => false,
:namespace => 'foo',
:readbuf_size => 4096
#cache.servers += [ "10.0.0.15:11211:5" ]
#cache.c_threshold = 10_000
#cache.compression = true
# Cache simple values with simple String or Symbol keys
cache["my_key"] = "Some value"
cache[
ther_key] = "Another value"
# ...or more-complex values
cache["object_key"] = { 'complex' => [ "object", 2, 4 ] }
# ...or more-complex keys
cache[ Time::now.to_a[1..7] ] ||= 0
# ...or both
#cache[userObject] = { :attempts => 0, :edges => [], :nodes => [] }
val = cache["my_key"] # => "Some value"
val = cache["object_key"] # => {"complex" => ["object",2,4]}
render_text val['complex'][2] # => 4
说明:'192.168.0.31:11211'是memcached Server所运行的服务器地址和端口.
gem install Ruby-MemCache --remote
使用以下语句即可将你需要存储Object(因为Ruby中一切者为Object)到MemCache中:
require 'rubygems'
require_gem 'Ruby-MemCache'
#ruquire 'memcache'
cache = MemCache::new '192.168.0.31:11211',
# '10.0.0.17:11211:3', # weighted
:debug => true,
:c_threshold => 100_000,
:compression => false,
:namespace => 'foo',
:readbuf_size => 4096
#cache.servers += [ "10.0.0.15:11211:5" ]
#cache.c_threshold = 10_000
#cache.compression = true
# Cache simple values with simple String or Symbol keys
cache["my_key"] = "Some value"
cache[
![](http://www.railser.com/images/smilies/shocked.gif)
# ...or more-complex values
cache["object_key"] = { 'complex' => [ "object", 2, 4 ] }
# ...or more-complex keys
cache[ Time::now.to_a[1..7] ] ||= 0
# ...or both
#cache[userObject] = { :attempts => 0, :edges => [], :nodes => [] }
val = cache["my_key"] # => "Some value"
val = cache["object_key"] # => {"complex" => ["object",2,4]}
render_text val['complex'][2] # => 4
说明:'192.168.0.31:11211'是memcached Server所运行的服务器地址和端口.