Class: Memcached::Rails
Overview
A legacy compatibility wrapper for the Memcached class. It has basic compatibility with the memcache-client API.
Direct Known Subclasses
Constant Summary
Constants inherited from Memcached
BEHAVIORS, BEHAVIOR_VALUES, CONVERSION_FACTORS, DEFAULTS, DIRECT_VALUE_BEHAVIORS, DISTRIBUTION_VALUES, EMPTY_STRUCT, ERRNO_HASH, EXCEPTIONS, FLAGS, HASH_VALUES, IGNORED, Lib, VERSION
Instance Attribute Summary
Attributes inherited from Memcached
Instance Method Summary collapse
-
#add(key, value, ttl = @default_ttl, raw = false) ⇒ Object
Wraps Memcached#add so that it doesn’t raise.
-
#append(*args) ⇒ Object
Wraps Memcached#append so that it doesn’t raise.
-
#cas(key, ttl = @default_ttl, raw = false, &block) ⇒ Object
(also: #compare_and_swap)
Wraps Memcached#cas so that it doesn’t raise.
-
#decr(*args) ⇒ Object
Wraps Memcached#decr so that it doesn’t raise.
-
#delete(key, *options) ⇒ Object
Wraps Memcached#delete so that it doesn’t raise.
-
#get(key, raw = false) ⇒ Object
(also: #[])
Wraps Memcached#get so that it doesn’t raise.
-
#get_multi(keys, raw = false) ⇒ Object
Wraps Memcached#get.
-
#incr(*args) ⇒ Object
Wraps Memcached#incr so that it doesn’t raise.
-
#initialize(*args) ⇒ Rails
constructor
See Memcached#new for details.
-
#namespace ⇒ Object
Namespace accessor.
-
#prepend(*args) ⇒ Object
Wraps Memcached#prepend so that it doesn’t raise.
-
#set(key, value, ttl = @default_ttl, raw = false) ⇒ Object
(also: #[]=)
Wraps Memcached#set.
Methods inherited from Memcached
#clone, #decrement, #destroy_credentials, finalize, #flush, #increment, load_constants, #quit, #replace, #reset, #server_by_key, #servers, #set_credentials, #set_servers, #stats
Constructor Details
#initialize(*args) ⇒ Rails
See Memcached#new for details.
13 14 15 16 17 18 19 20 21 |
# File 'lib/memcached/rails.rb', line 13 def initialize(*args) opts = args.last.is_a?(Hash) ? args.pop : {} servers = Array( args.any? ? args.unshift : opts.delete(:servers) ).flatten.compact opts[:prefix_key] ||= opts[:namespace] super(servers, opts) end |
Instance Method Details
#add(key, value, ttl = @default_ttl, raw = false) ⇒ Object
Wraps Memcached#add so that it doesn’t raise.
49 50 51 52 53 54 |
# File 'lib/memcached/rails.rb', line 49 def add(key, value, ttl=@default_ttl, raw=false) super(key, value, ttl, !raw) true rescue NotStored false end |
#append(*args) ⇒ Object
Wraps Memcached#append so that it doesn’t raise.
75 76 77 78 |
# File 'lib/memcached/rails.rb', line 75 def append(*args) super rescue NotStored end |
#cas(key, ttl = @default_ttl, raw = false, &block) ⇒ Object Also known as: compare_and_swap
Wraps Memcached#cas so that it doesn’t raise. Doesn’t set anything if no value is present.
31 32 33 34 |
# File 'lib/memcached/rails.rb', line 31 def cas(key, ttl=@default_ttl, raw=false, &block) super(key, ttl, !raw, &block) rescue NotFound end |
#decr(*args) ⇒ Object
Wraps Memcached#decr so that it doesn’t raise.
69 70 71 72 |
# File 'lib/memcached/rails.rb', line 69 def decr(*args) super rescue NotFound end |
#delete(key, *options) ⇒ Object
Wraps Memcached#delete so that it doesn’t raise.
57 58 59 60 |
# File 'lib/memcached/rails.rb', line 57 def delete(key, *) super(key) rescue NotFound end |
#get(key, raw = false) ⇒ Object Also known as: []
Wraps Memcached#get so that it doesn’t raise. This has the side-effect of preventing you from storing nil
values.
25 26 27 28 |
# File 'lib/memcached/rails.rb', line 25 def get(key, raw=false) super(key, !raw) rescue NotFound end |
#get_multi(keys, raw = false) ⇒ Object
Wraps Memcached#get.
39 40 41 |
# File 'lib/memcached/rails.rb', line 39 def get_multi(keys, raw=false) get_orig(keys, !raw) end |
#incr(*args) ⇒ Object
Wraps Memcached#incr so that it doesn’t raise.
63 64 65 66 |
# File 'lib/memcached/rails.rb', line 63 def incr(*args) super rescue NotFound end |
#namespace ⇒ Object
Namespace accessor.
87 88 89 |
# File 'lib/memcached/rails.rb', line 87 def namespace [:prefix_key] end |
#prepend(*args) ⇒ Object
Wraps Memcached#prepend so that it doesn’t raise.
81 82 83 84 |
# File 'lib/memcached/rails.rb', line 81 def prepend(*args) super rescue NotStored end |
#set(key, value, ttl = @default_ttl, raw = false) ⇒ Object Also known as: []=
Wraps Memcached#set.
44 45 46 |
# File 'lib/memcached/rails.rb', line 44 def set(key, value, ttl=@default_ttl, raw=false) super(key, value, ttl, !raw) end |