Class: PansophyAuthenticator::Cache

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

Constant Summary collapse

CACHE_KEY =
'pansophy_authenticator_application_keys'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(cache_store) ⇒ Cache

Returns a new instance of Cache.



9
10
11
# File 'lib/pansophy_authenticator/cache.rb', line 9

def initialize(cache_store)
  @cache_store = cache_store
end

Instance Method Details

#deleteObject



21
22
23
# File 'lib/pansophy_authenticator/cache.rb', line 21

def delete
  @cache_store.delete CACHE_KEY
end

#exist?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/pansophy_authenticator/cache.rb', line 25

def exist?
  @cache_store.exist? CACHE_KEY
end

#fetchObject



29
30
31
32
33
34
35
# File 'lib/pansophy_authenticator/cache.rb', line 29

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

#readObject



13
14
15
# File 'lib/pansophy_authenticator/cache.rb', line 13

def read
  JSON.parse(@cache_store.read(CACHE_KEY))
end

#write(value) ⇒ Object



17
18
19
# File 'lib/pansophy_authenticator/cache.rb', line 17

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