Class: RackJwtAegis::MemoryAdapter
- Inherits:
-
CacheAdapter
- Object
- CacheAdapter
- RackJwtAegis::MemoryAdapter
- Defined in:
- lib/rack_jwt_aegis/cache_adapter.rb
Overview
Memory-based cache adapter (for development/testing)
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(options = {}) ⇒ MemoryAdapter
constructor
A new instance of MemoryAdapter.
- #read(key) ⇒ Object
- #write(key, value, expires_in: nil) ⇒ Object
Methods inherited from CacheAdapter
Constructor Details
#initialize(options = {}) ⇒ MemoryAdapter
Returns a new instance of MemoryAdapter.
72 73 74 75 76 77 |
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 72 def initialize( = {}) super @store = {} @expires = {} @mutex = Mutex.new end |
Instance Method Details
#clear ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 111 def clear @mutex.synchronize do @store.clear @expires.clear true end end |
#delete(key) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 102 def delete(key) @mutex.synchronize do key_str = key.to_s @store.delete(key_str) @expires.delete(key_str) true end end |
#read(key) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 79 def read(key) @mutex.synchronize do cleanup_expired value = @store[key.to_s] deserialize_value(value) end end |
#write(key, value, expires_in: nil) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rack_jwt_aegis/cache_adapter.rb', line 87 def write(key, value, expires_in: nil) @mutex.synchronize do key_str = key.to_s @store[key_str] = serialize_value(value) if expires_in @expires[key_str] = Time.now + expires_in else @expires.delete(key_str) end true end end |