Class: OmniauthOpenidFederation::CacheAdapter::RailsCacheAdapter
- Inherits:
-
Object
- Object
- OmniauthOpenidFederation::CacheAdapter::RailsCacheAdapter
- Defined in:
- lib/omniauth_openid_federation/cache_adapter.rb
Overview
Adapter for Rails/ActiveSupport cache stores Wraps Rails.cache or ActiveSupport::Cache::Store to provide consistent interface
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #fetch(key, expires_in: nil, &block) ⇒ Object
-
#initialize(cache_store) ⇒ RailsCacheAdapter
constructor
A new instance of RailsCacheAdapter.
- #read(key) ⇒ Object
- #write(key, value, expires_in: nil) ⇒ Object
Constructor Details
#initialize(cache_store) ⇒ RailsCacheAdapter
Returns a new instance of RailsCacheAdapter.
142 143 144 |
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 142 def initialize(cache_store) @cache_store = cache_store end |
Instance Method Details
#clear ⇒ Object
168 169 170 |
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 168 def clear @cache_store.clear if @cache_store.respond_to?(:clear) end |
#delete(key) ⇒ Object
164 165 166 |
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 164 def delete(key) @cache_store.delete(key) end |
#fetch(key, expires_in: nil, &block) ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 146 def fetch(key, expires_in: nil, &block) = {} [:expires_in] = expires_in if expires_in # Handle nil key gracefully return block.call if key.nil? && block_given? @cache_store.fetch(key, , &block) end |
#read(key) ⇒ Object
154 155 156 |
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 154 def read(key) @cache_store.read(key) end |
#write(key, value, expires_in: nil) ⇒ Object
158 159 160 161 162 |
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 158 def write(key, value, expires_in: nil) = {} [:expires_in] = expires_in if expires_in @cache_store.write(key, value, ) end |