Module: Memflash::CachingLayer

Defined in:
lib/memflash.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/memflash.rb', line 19

def [](key)
  value_in_hash = super
  if memflashed?(key, value_in_hash)
    Rails.cache.read(value_in_hash)
  else
    value_in_hash
  end
end

#[]=(key, value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/memflash.rb', line 8

def []=(key, value)
  value_for_hash = value

  if value.kind_of?(String) && value.length >= Memflash.threshold
    value_for_hash = memflash_key(key)
    Rails.cache.write(value_for_hash, value)
  end

  super(key, value_for_hash)
end