Class: Dbviewer::Cache::InMemory
- Defined in:
- lib/dbviewer/cache/in_memory.rb
Overview
InMemory cache storage for Dbviewer It provides an abstraction layer for managing caches efficiently
Instance Method Summary collapse
-
#delete(key) ⇒ Object?
Delete a specific cache entry by key.
-
#fetch(key, options = {}) { ... } ⇒ Object
Fetch data from cache or execute block if not found/expired.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Dbviewer::Cache::Base
Instance Method Details
#delete(key) ⇒ Object?
Delete a specific cache entry by key
28 29 30 31 |
# File 'lib/dbviewer/cache/in_memory.rb', line 28 def delete(key) deleted_entry = @unified_cache.delete(key) deleted_entry&.fetch(:value) end |
#fetch(key, options = {}) { ... } ⇒ Object
Fetch data from cache or execute block if not found/expired
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dbviewer/cache/in_memory.rb', line 12 def fetch(key, = {}, &block) cache_entry = @unified_cache[key] custom_expiry = [:expires_in] || @cache_expiry return cache_entry[:value] if cache_entry && !cache_expired?(cache_entry, custom_expiry) result = block.call @unified_cache[key] = { value: result, created_at: Time.now } result end |