Sha256: aac54ed85ed62ed00e68e1266bc1400b40c30ddc141c8e7cce185b99d98d6802
Contents?: true
Size: 1.19 KB
Versions: 46
Compression:
Stored size: 1.19 KB
Contents
class Card class Cache # 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. class Temporary attr_reader :store def initialize @store = {} end # @param key [String] def read key return unless @store.key? key @store[key] end # @param key [String] def write key, value @store[key] = value end # @param key [String] def fetch key, &_block read(key) || write(key, yield) end # @param key [String] def delete key @store.delete key end def dump @store.each do |k, v| p "#{k} --> #{v.inspect[0..30]}" end end def reset @store = {} end # @param key [String] def exist? key @store.key? key end end end end
Version data entries
46 entries across 46 versions & 1 rubygems