Class: OpenID::Store::Memory

### Home Classes Methods

### In Files

- lib/openid/store/memory.rb

### Parent

OpenID::Store::Interface

### Methods

- ::new
- #cleanup_associations
- #cleanup_nonces
- #deepcopy
- #get_association
- #remove_association
- #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::Memory

An in-memory implementation of Store. This class is mainly used for testing, though it may be useful for long-running single process apps. Note that this store is NOT thread-safe.

You should probably be looking at OpenID::Store::Filesystem

### Public Class Methods

new() click to toggle source

    # File lib/openid/store/memory.rb, line 11
    def initialize
      @associations = Hash.new { |hash, key| hash[key] = {} }
      @nonces = {}
    end

### Public Instance Methods

cleanup_associations() click to toggle source

    # File lib/openid/store/memory.rb, line 50
    def cleanup_associations
      count = 0
      @associations.each{|server_url, assocs|
        assocs.each{|handle, assoc|
          if assoc.expires_in == 0
            assocs.delete(handle)
            count += 1
          end
        }
      }
      return count
    end

cleanup_nonces() click to toggle source

    # File lib/openid/store/memory.rb, line 63
    def cleanup_nonces
      count = 0
      now = Time.now.to_i
      @nonces.each{|nonce, timestamp|
        if (timestamp - now).abs > Nonce.skew
          @nonces.delete(nonce)
          count += 1
        end
      }
      return count
    end

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

    # File lib/openid/store/memory.rb, line 21
    def get_association(server_url, handle=nil)
      assocs = @associations[server_url]
      assoc = nil
      if handle
        assoc = assocs[handle]
      else
        assoc = assocs.values.sort{|a,b| a.issued <=> b.issued}[-1]
      end

      return assoc
    end

remove_association(server_url, handle) click to toggle source

    # File lib/openid/store/memory.rb, line 33
    def remove_association(server_url, handle)
      assocs = @associations[server_url]
      if assocs.delete(handle)
        return true
      else
        return false
      end
    end

store_association(server_url, assoc) click to toggle source

    # File lib/openid/store/memory.rb, line 16
    def store_association(server_url, assoc)
      assocs = @associations[server_url]
      @associations[server_url] = assocs.merge({assoc.handle => deepcopy(assoc)})
    end

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

    # File lib/openid/store/memory.rb, line 42
    def use_nonce(server_url, timestamp, salt)
      return false if (timestamp - Time.now.to_i).abs > Nonce.skew
      nonce = [server_url, timestamp, salt].join('')
      return false if @nonces[nonce]
      @nonces[nonce] = timestamp
      return true
    end

### Protected Instance Methods

deepcopy(o) click to toggle source

    # File lib/openid/store/memory.rb, line 77
    def deepcopy(o)
      Marshal.load(Marshal.dump(o))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.