Class: OpenID::Store::Memcache
- Inherits:
-
Interface
- Object
- Interface
- OpenID::Store::Memcache
- Defined in:
- lib/openid/store/memcache.rb
Instance Method Summary collapse
- #get_association(server_url, handle = nil) ⇒ Object
-
#initialize(*addresses) ⇒ Memcache
constructor
A new instance of Memcache.
- #remove_association(server_url, handle) ⇒ Object
- #store_association(server_url, assoc) ⇒ Object
- #use_nonce(server_url, timestamp, salt) ⇒ Object
Constructor Details
#initialize(*addresses) ⇒ Memcache
Returns a new instance of Memcache.
11 12 13 14 15 16 17 |
# File 'lib/openid/store/memcache.rb', line 11 def initialize(*addresses) addresses = addresses.flatten addresses = ['localhost'] if addresses.empty? @addresses = addresses @connection = MemCache.new(@addresses) raise 'No memcache servers' unless @connection.servers.any? { |s| s.alive? } end |
Instance Method Details
#get_association(server_url, handle = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/openid/store/memcache.rb', line 30 def get_association(server_url, handle = nil) if handle @connection.get(association_key(server_url, handle)) else server_key = association_server_key(server_url) assocs = @connection.get(server_key) return if assocs.nil? || assocs.empty? last_key = assocs[assocs.keys.sort.last] @connection.get(last_key) end end |
#remove_association(server_url, handle) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/openid/store/memcache.rb', line 43 def remove_association(server_url, handle) server_key = association_server_key(server_url) assoc_key = association_key(server_url, handle) assocs = @connection.get(server_key) return false unless assocs && assocs.has_value?(assoc_key) assocs = assocs.delete_if { |key, value| value == assoc_key } @connection.set(server_key, assocs) @connection.delete(assoc_key) return true end |
#store_association(server_url, assoc) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/openid/store/memcache.rb', line 19 def store_association(server_url, assoc) server_key = association_server_key(server_url) assoc_key = association_key(server_url, assoc.handle) assocs = @connection.get(server_key) || {} assocs[assoc.issued] = assoc_key @connection.set(server_key, assocs) @connection.set(assoc_key, assoc, assoc.lifetime) end |
#use_nonce(server_url, timestamp, salt) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/openid/store/memcache.rb', line 58 def use_nonce(server_url, , salt) return false if @connection.get(nonce_key(server_url, salt)) return false if ( - Time.now.to_i).abs > OpenID::Nonce.skew @connection.set(nonce_key(server_url, salt), , OpenID::Nonce.skew) return true end |