Class: Sym::App::Password::Cache

Inherits:
Object
  • Object
show all
Includes:
Singleton, Extensions::WithRetry, Extensions::WithTimeout
Defined in:
lib/sym/app/password/cache.rb

Overview

Provider is the primary implementation of the underlying cache. It should support the following API:

def initialize(*args, **opts, &block)
end

def read(key)
end

def write(key, value, expire_timeout_seconds)
end

it must be intantiatable via #new

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Extensions::WithTimeout

#with_timeout

Methods included from Extensions::WithRetry

#with_retry

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



33
34
35
# File 'lib/sym/app/password/cache.rb', line 33

def enabled
  @enabled
end

#providerObject

Returns the value of attribute provider.



33
34
35
# File 'lib/sym/app/password/cache.rb', line 33

def provider
  @provider
end

#timeoutObject

Returns the value of attribute timeout.



33
34
35
# File 'lib/sym/app/password/cache.rb', line 33

def timeout
  @timeout
end

#verboseObject

Returns the value of attribute verbose.



33
34
35
# File 'lib/sym/app/password/cache.rb', line 33

def verbose
  @verbose
end

Instance Method Details

#[](key) ⇒ Object



44
45
46
47
# File 'lib/sym/app/password/cache.rb', line 44

def [](key)
  cache = self
  operation { cache.provider.read(cache.md5(key)) }
end

#[]=(key, value) ⇒ Object



49
50
51
52
# File 'lib/sym/app/password/cache.rb', line 49

def []=(key, value)
  cache = self
  operation { cache.provider.write(cache.md5(key), value, cache.timeout) }
end

#configure(**opts) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/sym/app/password/cache.rb', line 35

def configure(**opts)
  self.enabled = opts[:enabled]
  self.verbose = opts[:verbose]
  self.timeout = opts[:timeout] || ::Sym::Configuration.config.password_cache_timeout
  self.provider = Providers.provider(opts[:provider], **(opts[:provider_opts] || {}))
  self.enabled = false unless self.provider
  self
end

#md5(string) ⇒ Object



54
55
56
# File 'lib/sym/app/password/cache.rb', line 54

def md5(string)
  Digest::MD5.base64digest(string)
end