Class: OmniauthOpenidFederation::CacheAdapter::RailsCacheAdapter

Inherits:
Object
  • Object
show all
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

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

#clearObject



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)
  options = {}
  options[:expires_in] = expires_in if expires_in
  # Handle nil key gracefully
  return block.call if key.nil? && block_given?
  @cache_store.fetch(key, options, &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)
  options = {}
  options[:expires_in] = expires_in if expires_in
  @cache_store.write(key, value, options)
end