class Card::Cache::Temporary
The {Temporary} cache is intended for a single request, script, migration, etc. It allows you to alter a card and then retrieve the card with those alterations intact without saving those changes to the database.
In practice, it’s a set of Cache-like methods for using a simple Hash.
Unlike the Persistent
cache, the Temporary
cache can handle objects with singleton classes.
Attributes
store[R]
Public Class Methods
new()
click to toggle source
# File lib/card/cache/temporary.rb, line 16 def initialize @store = {} end
Public Instance Methods
delete(key)
click to toggle source
@param key [String]
# File lib/card/cache/temporary.rb, line 38 def delete key @store.delete key end
dump()
click to toggle source
# File lib/card/cache/temporary.rb, line 42 def dump @store.each do |k, v| p "#{k} --> #{v.inspect[0..30]}" end end
exist?(key)
click to toggle source
@param key [String]
# File lib/card/cache/temporary.rb, line 53 def exist? key @store.key? key end
fetch(key) { || ... }
click to toggle source
@param key [String]
# File lib/card/cache/temporary.rb, line 33 def fetch key, &_block read(key) || write(key, yield) end
read(key)
click to toggle source
@param key [String]
# File lib/card/cache/temporary.rb, line 21 def read key return unless @store.key? key @store[key] end
reset()
click to toggle source
# File lib/card/cache/temporary.rb, line 48 def reset @store = {} end
write(key, value)
click to toggle source
@param key [String]
# File lib/card/cache/temporary.rb, line 28 def write key, value @store[key] = value end