Class: GithubAuthentication::Cache
- Inherits:
-
Object
- Object
- GithubAuthentication::Cache
- Defined in:
- lib/github_authentication/cache.rb
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(storage:, key: "") ⇒ Cache
constructor
storage = ActiveSupport::Cache.
- #read ⇒ Object
- #write(token) ⇒ Object
Constructor Details
#initialize(storage:, key: "") ⇒ Cache
storage = ActiveSupport::Cache
8 9 10 11 |
# File 'lib/github_authentication/cache.rb', line 8 def initialize(storage:, key: "") @storage = storage @key = "github:authentication:#{key}" end |
Instance Method Details
#clear ⇒ Object
22 23 24 |
# File 'lib/github_authentication/cache.rb', line 22 def clear @storage.delete(@key) end |
#read ⇒ Object
13 14 15 16 |
# File 'lib/github_authentication/cache.rb', line 13 def read json = @storage.read(@key) Token.from_json(json) end |
#write(token) ⇒ Object
18 19 20 |
# File 'lib/github_authentication/cache.rb', line 18 def write(token) @storage.write(@key, token.to_json, expires_in: token.expires_in) end |