memcache.rb

Path: lib/memcache.rb  (CVS)
Last Update: Thu Aug 25 14:54:49 MDT 2005

A Ruby client library for memcached (memory cache daemon)

Synopsis

  require 'memcache'

  cache = MemCache::new '10.0.0.15:11211',
                       '10.0.0.15:11212',
                       '10.0.0.17:11211:3', # weighted
                       :debug => true,
                       :c_threshold => 100_000,
                       :compression => false,
                       :namespace => 'foo'
  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[:other_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]}
  print val['complex'][2]             # => 4

Notes

  • Symbols are stringified currently because that’s the only way to guarantee that they hash to the same value across processes.

Known Bugs

  • If one or more memcacheds error when asked for ‘map’ or ‘malloc’ stats, it won’t be possible to retrieve them from any of the other servers, either. This is due to the way that the client handles server error conditions, and needs rethinking.

Authors

  • Michael Granger <ged@FaerieMUD.org>

Thanks to Martin Chase and Rick Bradley for peer review, bugfixes, and suggestions.

Copyright

Copyright © 2003-2005 The FaerieMUD Consortium. All rights reserved.

This module is free software. You may use, modify, and/or redistribute this software under the same terms as Ruby.

Subversion Id

 $Id: memcache.rb 72 2005-08-25 15:14:18Z ged $

Required files

io/reactor   socket   sync   timeout   zlib   uri  

[Validate]