Class: ToggleCraft::CacheAdapters::MemoryAdapter
- Inherits:
-
Object
- Object
- ToggleCraft::CacheAdapters::MemoryAdapter
- Defined in:
- lib/togglecraft/cache_adapters/memory_adapter.rb
Overview
In-memory cache adapter using thread-safe Concurrent::Map Suitable for single-process applications
Instance Method Summary collapse
-
#clear ⇒ Object
Clear all values from the store.
-
#delete(key) ⇒ Boolean
Delete a value from the store.
-
#get(key) ⇒ Object?
Get a value from the store.
-
#has?(key) ⇒ Boolean
Check if a key exists in the store.
-
#initialize ⇒ MemoryAdapter
constructor
A new instance of MemoryAdapter.
-
#keys ⇒ Array<String>
Get all keys in the store.
-
#set(key, value) ⇒ Object
Set a value in the store.
Constructor Details
#initialize ⇒ MemoryAdapter
Returns a new instance of MemoryAdapter.
10 11 12 |
# File 'lib/togglecraft/cache_adapters/memory_adapter.rb', line 10 def initialize @store = Concurrent::Map.new end |
Instance Method Details
#clear ⇒ Object
Clear all values from the store
36 37 38 |
# File 'lib/togglecraft/cache_adapters/memory_adapter.rb', line 36 def clear @store.clear end |
#delete(key) ⇒ Boolean
Delete a value from the store
31 32 33 |
# File 'lib/togglecraft/cache_adapters/memory_adapter.rb', line 31 def delete(key) !@store.delete(key).nil? end |
#get(key) ⇒ Object?
Get a value from the store
17 18 19 |
# File 'lib/togglecraft/cache_adapters/memory_adapter.rb', line 17 def get(key) @store[key] end |
#has?(key) ⇒ Boolean
Check if a key exists in the store
43 44 45 |
# File 'lib/togglecraft/cache_adapters/memory_adapter.rb', line 43 def has?(key) @store.key?(key) end |
#keys ⇒ Array<String>
Get all keys in the store
49 50 51 |
# File 'lib/togglecraft/cache_adapters/memory_adapter.rb', line 49 def keys @store.keys end |
#set(key, value) ⇒ Object
Set a value in the store
24 25 26 |
# File 'lib/togglecraft/cache_adapters/memory_adapter.rb', line 24 def set(key, value) @store[key] = value end |