Class: ActiveSupport::Cache::CachePipe
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ActiveSupport::Cache::CachePipe
- Defined in:
- lib/active_support/cache/cache_pipe.rb
Defined Under Namespace
Classes: WrappedNil
Constant Summary collapse
- NIL_VALUE =
WrappedNil.new
Instance Method Summary collapse
- #fetch(name, options = nil) ⇒ Object
-
#initialize(transformation, *store_options) ⇒ CachePipe
constructor
In your environment configruation: config.cache_store = :cache_pipe, :wrap_nil, :dalli_store, { value_max_bytes: 10485760, expires_in: 86400 }.
- #read(name, options = nil) ⇒ Object
- #write(name, value, options = nil) ⇒ Object
Constructor Details
#initialize(transformation, *store_options) ⇒ CachePipe
In your environment configruation:
config.cache_store = :cache_pipe, :wrap_nil, :dalli_store, { value_max_bytes: 10485760, expires_in: 86400 }
will cause a call to:
ActiveSupport::Cache::CachePipe.new(:wrap_nil, :dalli_store, { value_max_bytes: 10485760, expires_in: 86400 })
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_support/cache/cache_pipe.rb', line 15 def initialize transformation, * super ActiveSupport::Cache.lookup_store(*) case transformation when :wrap_nil @transform_read = :unwrap_nil @transform_write = :wrap_nil else raise "Invalid transformation #{transformation}. Valid values are: :wrap_nil" end end |
Instance Method Details
#fetch(name, options = nil) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/active_support/cache/cache_pipe.rb', line 26 def fetch name, =nil if block_given? transform_read __getobj__.fetch(name, ) { transform_write(yield) } else transform_read __getobj__.fetch(name, ) end end |
#read(name, options = nil) ⇒ Object
34 35 36 |
# File 'lib/active_support/cache/cache_pipe.rb', line 34 def read name, =nil transform_read __getobj__.read(name, ) end |
#write(name, value, options = nil) ⇒ Object
38 39 40 |
# File 'lib/active_support/cache/cache_pipe.rb', line 38 def write name, value, =nil __getobj__.write name, transform_write(value), end |