Sha256: 859c1c964072c143ae361d17dc36b85c1ad35633cc74f02b1a394bd09848e42d

Contents?: true

Size: 510 Bytes

Versions: 3

Compression:

Stored size: 510 Bytes

Contents

# frozen_string_literal: true

require 'github_authentication/token'

module GithubAuthentication
  class Cache
    # storage = ActiveSupport::Cache
    def initialize(storage:, key: '')
      @storage = storage
      @key = "github:authentication:#{key}"
    end

    def read
      json = @storage.read(@key)
      Token.from_json(json)
    end

    def write(token)
      @storage.write(@key, token.to_json, expires_in: token.expires_in)
    end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
github-authentication-1.0.2 lib/github_authentication/cache.rb
github-authentication-1.0.1 lib/github_authentication/cache.rb
github-authentication-1.0.0 lib/github_authentication/cache.rb