Class: RackJwtAegis::CacheAdapter
- Inherits:
-
Object
- Object
- RackJwtAegis::CacheAdapter
show all
- Defined in:
- lib/rack_jwt_aegis/cache_adapter.rb
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ CacheAdapter
Returns a new instance of CacheAdapter.
20
21
22
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 20
def initialize(options = {})
@options = options
end
|
Class Method Details
.build(store_type, options = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 5
def self.build(store_type, options = {})
case store_type
when :memory, :memory_store
MemoryAdapter.new(options)
when :redis, :redis_cache_store
RedisAdapter.new(options)
when :memcached, :mem_cache_store
MemcachedAdapter.new(options)
when :solid_cache, :solid_cache_store
SolidCacheAdapter.new(options)
else
raise ConfigurationError, "Unsupported cache store: #{store_type}"
end
end
|
Instance Method Details
#clear ⇒ Object
41
42
43
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 41
def clear
raise NotImplementedError, 'Subclass must implement #clear'
end
|
#delete(key) ⇒ Object
33
34
35
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 33
def delete(key)
raise NotImplementedError, 'Subclass must implement #delete'
end
|
#deserialize_value(value, _original_type = nil) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 57
def deserialize_value(value, _original_type = nil)
return value if value.nil?
return value unless value.is_a?(String)
begin
JSON.parse(value)
rescue JSON::ParserError
value
end
end
|
#exist?(key) ⇒ Boolean
37
38
39
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 37
def exist?(key)
!read(key).nil?
end
|
#read(key) ⇒ Object
Abstract methods - must be implemented by subclasses
25
26
27
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 25
def read(key)
raise NotImplementedError, 'Subclass must implement #read'
end
|
#serialize_value(value) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 48
def serialize_value(value)
case value
when String, Numeric, TrueClass, FalseClass, NilClass
value
else
JSON.generate(value)
end
end
|
#write(key, value, expires_in: nil) ⇒ Object
29
30
31
|
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 29
def write(key, value, expires_in: nil)
raise NotImplementedError, 'Subclass must implement #write'
end
|