Class: GithubAuthentication::ObjectCache

Inherits:
Object
  • Object
show all
Defined in:
lib/github_authentication/object_cache.rb

Instance Method Summary collapse

Constructor Details

#initializeObjectCache

Returns a new instance of ObjectCache.



7
8
9
# File 'lib/github_authentication/object_cache.rb', line 7

def initialize
  @cache = {}
end

Instance Method Details

#clear(key) ⇒ Object



30
31
32
# File 'lib/github_authentication/object_cache.rb', line 30

def clear(key)
  @cache.delete(key)
end

#read(key) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/github_authentication/object_cache.rb', line 11

def read(key)
  return unless @cache.key?(key)

  options = @cache[key][:options]
  if options.key?(:expires_at) && Time.now.utc > options[:expires_at]
    @cache.delete(key)
    return
  end

  @cache[key][:value]
end

#write(key, value, options = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/github_authentication/object_cache.rb', line 23

def write(key, value, options = {})
  if options.key?(:expires_in)
    options[:expires_at] = Time.now.utc + options[:expires_in]
  end
  @cache[key] = { value: value, options: options }
end