Class: GithubAuthentication::Cache

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

Instance Method Summary collapse

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

#clearObject



22
23
24
# File 'lib/github_authentication/cache.rb', line 22

def clear
  @storage.delete(@key)
end

#readObject



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