Class: Memcached::Rails

A legacy compatibility wrapper for the Memcached class. It has basic compatibility with the memcache-client API.

Constants

NameValue
DEFAULTS {}

Aliases

Old nameNew name
flush flush_all

Public Class Methods


new (*args)

See Memcached#new for details.

    # File lib/memcached/rails.rb, line 12
12:     def initialize(*args)
13:       opts = args.last.is_a?(Hash) ? args.pop : {}
14:       servers = Array(
15:         args.any? ? args.unshift : opts.delete(:servers)
16:       ).flatten.compact
17: 
18:       opts[:prefix_key] ||= opts[:namespace]
19:       super(servers, DEFAULTS.merge(opts))      
20:     end

Public Instance Methods




add (key, value, ttl=nil, raw=false)

Wraps Memcached#add so that it doesn‘t raise.

    # File lib/memcached/rails.rb, line 40
40:     def add(key, value, ttl=nil, raw=false)
41:       super(key, value, ttl, !raw)
42:       true
43:     rescue NotStored
44:       false    
45:     end

decr (*args)

Wraps Memcached#decr so that it doesn‘t raise.

    # File lib/memcached/rails.rb, line 60
60:     def decr(*args)
61:       super
62:     rescue NotFound
63:     end

delete (key)

Wraps Memcached#delete so that it doesn‘t raise.

    # File lib/memcached/rails.rb, line 48
48:     def delete(key)
49:       super
50:     rescue NotFound
51:     end

get (key, raw=false)

Wraps Memcached#get so that it doesn‘t raise. This has the side-effect of preventing you from storing nil values.

    # File lib/memcached/rails.rb, line 24
24:     def get(key, raw=false)
25:       super(key, !raw)
26:     rescue NotFound
27:     end

get_multi (*keys)

Wraps Memcached#get with multiple arguments.

    # File lib/memcached/rails.rb, line 30
30:     def get_multi(*keys)
31:       super(keys)
32:     end

incr (*args)

Wraps Memcached#incr so that it doesn‘t raise.

    # File lib/memcached/rails.rb, line 54
54:     def incr(*args)
55:       super
56:     rescue NotFound
57:     end

namespace ()

Namespace accessor.

    # File lib/memcached/rails.rb, line 66
66:     def namespace
67:       options[:prefix_key]
68:     end

set (key, value, ttl=nil, raw=false)

Wraps Memcached#set.

    # File lib/memcached/rails.rb, line 35
35:     def set(key, value, ttl=nil, raw=false)
36:       super(key, value, ttl, !raw)
37:     end