Sha256: 878aaac3c6ec09b4241f4ca0e60660cbaefe55788f3c27d84d5d72207411dca3

Contents?: true

Size: 627 Bytes

Versions: 3

Compression:

Stored size: 627 Bytes

Contents

# frozen_string_literal: true
module PansophyAuthenticator
  class Cache
    CACHE_KEY = 'pansophy_authenticator_application_keys'.freeze

    def initialize(cache_store)
      @cache_store = cache_store
    end

    def read
      @cache_store.read CACHE_KEY
    end

    def write(value)
      @cache_store.write CACHE_KEY, value
    end

    def delete
      @cache_store.delete CACHE_KEY
    end

    def exist?
      @cache_store.exist? CACHE_KEY
    end

    def fetch
      return read if exist?
      return nil unless block_given?
      yield(CACHE_KEY).tap do |value|
        write(value)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pansophy_authenticator-0.4.0 lib/pansophy_authenticator/cache.rb
pansophy_authenticator-0.3.0 lib/pansophy_authenticator/cache.rb
pansophy_authenticator-0.2.0 lib/pansophy_authenticator/cache.rb