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.
145 146 147 |
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 145 def initialize(cache_store) @cache_store = cache_store end |
Instance Method Details
#clear ⇒ Object
171 172 173 |
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 171 def clear @cache_store.clear if @cache_store.respond_to?(:clear) end |
#delete(key) ⇒ Object
167 168 169 |
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 167 def delete(key) @cache_store.delete(key) end |
#fetch(key, expires_in: nil, &block) ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 149 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
157 158 159 |
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 157 def read(key) @cache_store.read(key) end |
#write(key, value, expires_in: nil) ⇒ Object
161 162 163 164 165 |
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 161 def write(key, value, expires_in: nil) = {} [:expires_in] = expires_in if expires_in @cache_store.write(key, value, ) end |