Class: OmniauthOpenidFederation::CacheAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/omniauth_openid_federation/cache_adapter.rb

Defined Under Namespace

Classes: RailsCacheAdapter

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.adapterObject?

Get the configured cache adapter Automatically detects Rails.cache if available



39
40
41
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 39

def adapter
  @adapter ||= detect_adapter
end

Class Method Details

.available?Boolean

Check if caching is available



54
55
56
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 54

def available?
  !adapter.nil?
end

.clearvoid

This method returns an undefined value.

Clear all cache (if supported)



102
103
104
105
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 102

def clear
  return unless available?
  adapter.clear if adapter.respond_to?(:clear)
end

.delete(key) ⇒ void

This method returns an undefined value.

Delete a value from cache



94
95
96
97
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 94

def delete(key)
  return unless available?
  adapter.delete(key)
end

.fetch(key, expires_in: nil) { ... } ⇒ Object

Fetch a value from cache, or compute and cache it

Yields:

  • Block to compute value if not cached



64
65
66
67
68
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 64

def fetch(key, expires_in: nil, &block)
  return yield unless available? && block_given?

  adapter.fetch(key, expires_in: expires_in, &block)
end

.read(key) ⇒ Object?

Read a value from cache



74
75
76
77
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 74

def read(key)
  return nil unless available?
  adapter.read(key)
end

.reset!void

This method returns an undefined value.

Reset the cache adapter (useful for testing) Forces re-detection of cache adapter on next access



47
48
49
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 47

def reset!
  @adapter = nil
end

.write(key, value, expires_in: nil) ⇒ void

This method returns an undefined value.

Write a value to cache



85
86
87
88
# File 'lib/omniauth_openid_federation/cache_adapter.rb', line 85

def write(key, value, expires_in: nil)
  return unless available?
  adapter.write(key, value, expires_in: expires_in)
end