class CountedCacheItem
A container for items in a counted cache.
Constants
- EMPTY
A marker for empty items.
Attributes
count[R]
The reference count of this item.
data[W]
Let the data be set.
Public Class Methods
new(key)
click to toggle source
Setup an empty data item.
# File lib/counted_cache/counted_cache_item.rb, line 14 def initialize(key) @data = EMPTY @key = key @count = 0 end
Public Instance Methods
data()
click to toggle source
Retrieve the data, maintain a reference count.
# File lib/counted_cache/counted_cache_item.rb, line 32 def data @count += 1 @data end
empty?()
click to toggle source
Is this item empty?
# File lib/counted_cache/counted_cache_item.rb, line 21 def empty? @data == EMPTY end
purge(save_block)
click to toggle source
Erase the data associated with the given key.
# File lib/counted_cache/counted_cache_item.rb, line 26 def purge(save_block) save_block.call(@key, @data) @data = EMPTY end