Module: LruReduxStore::DupCoder
Overview
Vendored copy of ActiveSupport::Cache::MemoryStore::DupCoder (activesupport 8.1.3, MIT license). DupCoder is :nodoc: internal API, so we carry our own copy rather than referencing it: https://github.com/rails/rails/blob/v8.1.3/activesupport/lib/active_support/cache/memory_store.rb
Dups string values and marshals everything else so the cache never shares object references with callers. A write stores a private copy and every read returns a fresh one.
Constant Summary collapse
- MARSHAL_SIGNATURE =
"\x04\x08".b.freeze
Instance Method Summary collapse
Instance Method Details
#dump(entry) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/lru_redux_store/dup_coder.rb', line 17 def dump(entry) if entry.value && entry.value != true && !entry.value.is_a?(Numeric) ActiveSupport::Cache::Entry.new(dump_value(entry.value), expires_at: entry.expires_at, version: entry.version) else entry end end |
#dump_compressed(entry, threshold) ⇒ Object
25 26 27 28 |
# File 'lib/lru_redux_store/dup_coder.rb', line 25 def dump_compressed(entry, threshold) compressed_entry = entry.compressed(threshold) compressed_entry.compressed? ? compressed_entry : dump(entry) end |
#load(entry) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/lru_redux_store/dup_coder.rb', line 30 def load(entry) if !entry.compressed? && entry.value.is_a?(String) ActiveSupport::Cache::Entry.new(load_value(entry.value), expires_at: entry.expires_at, version: entry.version) else entry end end |