class Mongo::Auth::Aws::CredentialsCache
Thread safe cache to store AWS credentials.
@api private
Public Class Methods
instance()
click to toggle source
Get or create the singleton instance of the cache.
@return [ CredentialsCache ] The singleton instance.
# File lib/mongo/auth/aws/credentials_cache.rb, line 27 def self.instance @instance ||= new end
new()
click to toggle source
# File lib/mongo/auth/aws/credentials_cache.rb, line 31 def initialize @lock = Mutex.new @credentials = nil end
Public Instance Methods
clear()
click to toggle source
Clear the credentials from the cache.
# File lib/mongo/auth/aws/credentials_cache.rb, line 66 def clear @lock.synchronize do @credentials = nil end end
credentials()
click to toggle source
Get the credentials from the cache.
@return [ Aws::Credentials ] The cached credentials.
# File lib/mongo/auth/aws/credentials_cache.rb, line 48 def credentials @lock.synchronize do @credentials end end
credentials=(credentials)
click to toggle source
Set the credentials in the cache.
@param [ Aws::Credentials ] credentials The credentials to cache.
# File lib/mongo/auth/aws/credentials_cache.rb, line 39 def credentials=(credentials) @lock.synchronize do @credentials = credentials end end
fetch() { || ... }
click to toggle source
Fetch the credentials from the cache or yield to get them if they are not in the cache or have expired.
@return [ Aws::Credentials ] The cached credentials.
# File lib/mongo/auth/aws/credentials_cache.rb, line 58 def fetch @lock.synchronize do @credentials = yield if @credentials.nil? || @credentials.expired? @credentials end end