memcache

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所运行的服务器地址和端口.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值