Class: GithubAuthentication::ObjectCache
- Inherits:
-
Object
- Object
- GithubAuthentication::ObjectCache
- Defined in:
- lib/github_authentication/object_cache.rb
Instance Method Summary collapse
- #clear(key) ⇒ Object
-
#initialize ⇒ ObjectCache
constructor
A new instance of ObjectCache.
- #read(key) ⇒ Object
- #write(key, value, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ ObjectCache
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) = @cache[key][:options] if .key?(:expires_at) && Time.now.utc > [: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, = {}) if .key?(:expires_in) [:expires_at] = Time.now.utc + [:expires_in] end @cache[key] = { value: value, options: } end |