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.



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

#clearObject



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)
  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



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)
  options = {}
  options[:expires_in] = expires_in if expires_in
  @cache_store.write(key, value, options)
end