Class: ActiveSupport::Cache::Strategy::LocalCache::LocalStore
- Inherits:
-
ActiveSupport::Cache::Store
- Object
- ActiveSupport::Cache::Store
- ActiveSupport::Cache::Strategy::LocalCache::LocalStore
- Defined in:
- lib/active_support/cache/strategy/local_cache.rb
Overview
Simple memory backed cache. This cache is not thread safe and is intended only for serving as a temporary memory cache for a single thread.
Constant Summary
Constants inherited from ActiveSupport::Cache::Store
ActiveSupport::Cache::Store::DEFAULT_CODER
Instance Attribute Summary
Attributes inherited from ActiveSupport::Cache::Store
Instance Method Summary collapse
- #clear(options = nil) ⇒ Object
- #delete_entry(key, **options) ⇒ Object
-
#fetch_entry(key, options = nil) ⇒ Object
:nodoc:.
-
#initialize ⇒ LocalStore
constructor
A new instance of LocalStore.
- #read_entry(key, **options) ⇒ Object
- #read_multi_entries(keys, **options) ⇒ Object
-
#synchronize ⇒ Object
Don't allow synchronizing since it isn't thread safe.
- #write_entry(key, entry, **options) ⇒ Object
Methods inherited from ActiveSupport::Cache::Store
#cleanup, #decrement, #delete, #delete_matched, #delete_multi, #exist?, #fetch, #fetch_multi, #increment, #mute, #read, #read_multi, #silence!, #write, #write_multi
Constructor Details
#initialize ⇒ LocalStore
Returns a new instance of LocalStore.
38 39 40 41 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 38 def initialize super @data = {} end |
Instance Method Details
#clear(options = nil) ⇒ Object
48 49 50 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 48 def clear( = nil) @data.clear end |
#delete_entry(key, **options) ⇒ Object
73 74 75 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 73 def delete_entry(key, **) !!@data.delete(key) end |
#fetch_entry(key, options = nil) ⇒ Object
:nodoc:
77 78 79 80 81 82 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 77 def fetch_entry(key, = nil) # :nodoc: entry = @data.fetch(key) { @data[key] = yield } dup_entry = entry.dup dup_entry&.dup_value! dup_entry end |
#read_entry(key, **options) ⇒ Object
52 53 54 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 52 def read_entry(key, **) @data[key] end |
#read_multi_entries(keys, **options) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 56 def read_multi_entries(keys, **) values = {} keys.each do |name| entry = read_entry(name, **) values[name] = entry.value if entry end values end |
#synchronize ⇒ Object
Don't allow synchronizing since it isn't thread safe.
44 45 46 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 44 def synchronize # :nodoc: yield end |
#write_entry(key, entry, **options) ⇒ Object
67 68 69 70 71 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 67 def write_entry(key, entry, **) entry.dup_value! @data[key] = entry true end |