Class: ActiveSupport::Cache::CachePipe

Inherits:
SimpleDelegator
  • Object
show all
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

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, *store_options
  super ActiveSupport::Cache.lookup_store(*store_options)
  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, options=nil
  if block_given?
    transform_read __getobj__.fetch(name, options) { transform_write(yield) }
  else
    transform_read __getobj__.fetch(name, options)
  end
end

#read(name, options = nil) ⇒ Object



34
35
36
# File 'lib/active_support/cache/cache_pipe.rb', line 34

def read name, options=nil
  transform_read __getobj__.read(name, options)
end

#write(name, value, options = nil) ⇒ Object



38
39
40
# File 'lib/active_support/cache/cache_pipe.rb', line 38

def write name, value, options=nil
  __getobj__.write name, transform_write(value), options
end