Class: OpenID::Store::Memcache

### Home Classes Methods

### In Files

- lib/openid/store/memcache.rb

### Parent

OpenID::Store::Interface

### Methods

- ::new
- #assoc_key
- #cleanup
- #cleanup_associations
- #cleanup_nonces
- #delete
- #deserialize
- #expiry
- #get_association
- #remove_association
- #serialize
- #store_association
- #use_nonce

### Files

- LICENSE

### Class/Module Index

Quicksearch

- OpenID
- OpenID::AX
- OpenID::AX::AXMessage
- OpenID::AX::AttrInfo
- OpenID::AX::Error
- OpenID::AX::FetchRequest
- OpenID::AX::FetchResponse
- OpenID::AX::KeyValueMessage
- OpenID::AX::StoreRequest
- OpenID::AX::StoreResponse
- OpenID::AssertionError
- OpenID::Association
- OpenID::AssociationNegotiator
- OpenID::Consumer
- OpenID::Consumer::AssociationManager
- OpenID::Consumer::CancelResponse
- OpenID::Consumer::CheckIDRequest
- OpenID::Consumer::DiffieHellmanSHA1Session
- OpenID::Consumer::DiffieHellmanSHA256Session
- OpenID::Consumer::DiffieHellmanSession
- OpenID::Consumer::DiscoveredServices
- OpenID::Consumer::DiscoveryManager
- OpenID::Consumer::FailureResponse
- OpenID::Consumer::IdResHandler
- OpenID::Consumer::NoEncryptionSession
- OpenID::Consumer::Response
- OpenID::Consumer::Session
- OpenID::Consumer::SetupNeededResponse
- OpenID::Consumer::SuccessResponse
- OpenID::CryptUtil
- OpenID::DiffieHellman
- OpenID::DiscoveryFailure
- OpenID::Extension
- OpenID::FetchingError
- OpenID::HTTPRedirectLimitReached
- OpenID::HTTPResponse
- OpenID::HTTPStatusError
- OpenID::InvalidOpenIDNamespace
- OpenID::KVFormError
- OpenID::KVPostNetworkError
- OpenID::Message
- OpenID::Message::KeyNotFound
- OpenID::NamespaceAliasRegistrationError
- OpenID::NamespaceMap
- OpenID::Nonce
- OpenID::OAuth
- OpenID::OAuth::Request
- OpenID::OAuth::Response
- OpenID::OpenIDError
- OpenID::OpenIDServiceEndpoint
- OpenID::PAPE
- OpenID::PAPE::Request
- OpenID::PAPE::Response
- OpenID::ProtocolError
- OpenID::RealmVerificationRedirected
- OpenID::SReg
- OpenID::SReg::NamespaceError
- OpenID::SReg::Request
- OpenID::SReg::Response
- OpenID::SSLFetchingError
- OpenID::Server
- OpenID::Server::AlreadySigned
- OpenID::Server::AssociateRequest
- OpenID::Server::BaseServerSession
- OpenID::Server::CheckAuthRequest
- OpenID::Server::CheckIDRequest
- OpenID::Server::Decoder
- OpenID::Server::DiffieHellmanSHA1ServerSession
- OpenID::Server::DiffieHellmanSHA256ServerSession
- OpenID::Server::Encoder
- OpenID::Server::EncodingError
- OpenID::Server::MalformedReturnURL
- OpenID::Server::MalformedTrustRoot
- OpenID::Server::NoReturnToError
- OpenID::Server::OpenIDRequest
- OpenID::Server::OpenIDResponse
- OpenID::Server::PlainTextServerSession
- OpenID::Server::ProtocolError
- OpenID::Server::Server
- OpenID::Server::Signatory
- OpenID::Server::SigningEncoder
- OpenID::Server::UntrustedReturnURL
- OpenID::Server::VersionError
- OpenID::Server::WebResponse
- OpenID::ServerError
- OpenID::StandardFetcher
- OpenID::Store
- OpenID::Store::Filesystem
- OpenID::Store::Interface
- OpenID::Store::Memcache
- OpenID::Store::Memory
- OpenID::TrustRoot
- OpenID::TrustRoot::TrustRoot
- OpenID::TypeURIMismatch
- OpenID::UI
- OpenID::UI::Request
- OpenID::URINorm
- OpenID::UndefinedOpenIDNamespace
- OpenID::Util
- OpenID::Yadis
- OpenID::Yadis::BasicServiceEndpoint
- OpenID::Yadis::CompoundFilter
- OpenID::Yadis::DiscoveryResult
- OpenID::Yadis::TransformFilterMaker
- OpenID::Yadis::XRDSError
- OpenID::Yadis::XRDSFraud
- OpenID::Yadis::XRI
- OpenID::Yadis::XRI::ProxyResolver
- OpenID::Yadis::XRI::XRIHTTPError
- HMAC
- HMAC::Base
- HMAC::SHA1
- HMAC::SHA256
- HMAC::SHA384
- HMAC::SHA512
- Net
- Net::HTTP
- HTMLComment
- HTMLTag
- HTMLText
- HTMLToken
- HTMLTokenizer
- HTMLTokenizerError
- Object

No matching classes.

# OpenID::Store::Memcache

### Attributes

key_prefix[RW]

### Public Class Methods

new(cache_client, key_prefix='openid-store:') click to toggle source

    # File lib/openid/store/memcache.rb, line 11
    def initialize(cache_client, key_prefix='openid-store:')
      @cache_client = cache_client
      self.key_prefix = key_prefix
    end

### Public Instance Methods

assoc_key(server_url, assoc_handle=nil) click to toggle source

    # File lib/openid/store/memcache.rb, line 73
    def assoc_key(server_url, assoc_handle=nil)
      key = key_prefix + 'A' + server_url
      if assoc_handle
        key += '|' + assoc_handle
      end
      return key
    end

cleanup() click to toggle source

    # File lib/openid/store/memcache.rb, line 84
    def cleanup
    end

cleanup_associations() click to toggle source

    # File lib/openid/store/memcache.rb, line 87
    def cleanup_associations
    end

cleanup_nonces() click to toggle source

    # File lib/openid/store/memcache.rb, line 81
    def cleanup_nonces
    end

get_association(server_url, handle=nil) click to toggle source

Returns a Association object from storage that matches the server_url. Returns nil if no such association is found or if the one matching association is expired. (Is allowed to GC expired associations when found.)

    # File lib/openid/store/memcache.rb, line 32
    def get_association(server_url, handle=nil)
      serialized = @cache_client.get(assoc_key(server_url, handle))
      if serialized
        return deserialize(serialized)
      else
        return nil
      end
    end

remove_association(server_url, handle) click to toggle source

If there is a matching association, remove it from the store and return true, otherwise return false.

    # File lib/openid/store/memcache.rb, line 43
    def remove_association(server_url, handle)
      deleted = delete(assoc_key(server_url, handle))
      server_assoc = get_association(server_url)
      if server_assoc && server_assoc.handle == handle
        deleted = delete(assoc_key(server_url)) | deleted
      end
      return deleted
    end

store_association(server_url, association) click to toggle source

Put a Association object into storage. When implementing a store, don't assume that there are any limitations on the character set of the server_url. In particular, expect to see unescaped non-url-safe characters in the server_url field.

    # File lib/openid/store/memcache.rb, line 20
    def store_association(server_url, association)
      serialized = serialize(association)
      [nil, association.handle].each do |handle|
        key = assoc_key(server_url, handle)
        @cache_client.set(key, serialized, expiry(association.lifetime))
      end
    end

use_nonce(server_url, timestamp, salt) click to toggle source

Return true if the nonce has not been used before, and store it for a while to make sure someone doesn't try to use the same value again. Return false if the nonce has already been used or if the timestamp is not current. You can use OpenID::Store::Nonce::SKEW for your timestamp window. server_url: URL of the server from which the nonce originated timestamp: time the nonce was created in seconds since unix epoch salt: A random string that makes two nonces issued by a server in

    the same second unique

    # File lib/openid/store/memcache.rb, line 61
    def use_nonce(server_url, timestamp, salt)
      return false if (timestamp - Time.now.to_i).abs > Nonce.skew
      ts = timestamp.to_s # base 10 seconds since epoch
      nonce_key = key_prefix + 'N' + server_url + '|' + ts + '|' + salt
      result = @cache_client.add(nonce_key, '', expiry(Nonce.skew + 5))
      if result.is_a? String
        return !!(result =~ /^STORED/)
      else
        return !!(result)
      end
    end

### Protected Instance Methods

delete(key) click to toggle source

    # File lib/openid/store/memcache.rb, line 92
    def delete(key)
      result = @cache_client.delete(key)
      if result.is_a? String
        return !!(result =~ /^DELETED/)
      else
        return !!(result)
      end
    end

deserialize(assoc_str) click to toggle source

    # File lib/openid/store/memcache.rb, line 105
    def deserialize(assoc_str)
      Marshal.load(assoc_str)
    end

expiry(t) click to toggle source

Convert a lifetime in seconds into a memcache expiry value

    # File lib/openid/store/memcache.rb, line 110
    def expiry(t)
      Time.now.to_i + t
    end

serialize(assoc) click to toggle source

    # File lib/openid/store/memcache.rb, line 101
    def serialize(assoc)
      Marshal.dump(assoc)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.