Class: PansophyAuthenticator::Cache
- Inherits:
-
Object
- Object
- PansophyAuthenticator::Cache
- Defined in:
- lib/pansophy_authenticator/cache.rb
Constant Summary collapse
- CACHE_KEY =
'pansophy_authenticator_application_keys'.freeze
Instance Method Summary collapse
- #delete ⇒ Object
- #exist? ⇒ Boolean
- #fetch ⇒ Object
-
#initialize(cache_store) ⇒ Cache
constructor
A new instance of Cache.
- #read ⇒ Object
- #write(value) ⇒ Object
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
#delete ⇒ Object
21 22 23 |
# File 'lib/pansophy_authenticator/cache.rb', line 21 def delete @cache_store.delete CACHE_KEY end |
#exist? ⇒ Boolean
25 26 27 |
# File 'lib/pansophy_authenticator/cache.rb', line 25 def exist? @cache_store.exist? CACHE_KEY end |
#fetch ⇒ Object
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 |
#read ⇒ Object
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 |