Object
WARNING: all public methods of the class must operate on the @backend directly without calling each other. This is important because of the SynchronizedCacheBackend which uses a non-reentrant mutex for perfomance reasons.
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 5 def initialize(options = nil) @backend = {} end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 9 def [](key) @backend[key] end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 13 def []=(key, value) @backend[key] = value end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 86 def clear @backend.clear self end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 47 def compute(key) store_computed_value(key, yield(@backend[key])) end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 17 def compute_if_absent(key) if NULL != (stored_value = @backend.fetch(key, NULL)) stored_value else @backend[key] = yield end end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 41 def compute_if_present(key) if NULL != (stored_value = @backend.fetch(key, NULL)) store_computed_value(key, yield(stored_value)) end end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 73 def delete(key) @backend.delete(key) end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 77 def delete_pair(key, value) if pair?(key, value) @backend.delete(key) true else false end end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 91 def each_pair dupped_backend.each_pair do |k, v| yield k, v end self end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 59 def get_and_set(key, value) stored_value = @backend[key] @backend[key] = value stored_value end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 102 def get_or_default(key, default_value) @backend.fetch(key, default_value) end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 65 def key?(key) @backend.key?(key) end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 51 def merge_pair(key, value) if NULL == (stored_value = @backend.fetch(key, NULL)) @backend[key] = value else store_computed_value(key, yield(stored_value)) end end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 34 def replace_if_exists(key, new_value) if NULL != (stored_value = @backend.fetch(key, NULL)) @backend[key] = new_value stored_value end end
# File lib/thread_safe/non_concurrent_cache_backend.rb, line 25 def replace_pair(key, old_value, new_value) if pair?(key, old_value) @backend[key] = new_value true else false end end
Generated with the Darkfish Rdoc Generator 2.