lib/flipper/adapters/memoized.rb in flipper-0.3.0 vs lib/flipper/adapters/memoized.rb in flipper-0.4.0
- old
+ new
@@ -1,44 +1,51 @@
require 'set'
module Flipper
module Adapters
class Memoized
+ # Public
def initialize(adapter, cache = {})
@adapter = adapter
@cache = cache
end
+ # Public
def read(key)
@cache.fetch(key) {
@cache[key] = @adapter.read(key)
}
end
+ # Public
def write(key, value)
result = @adapter.write(key, value)
@cache.delete(key)
result
end
+ # Public
def delete(key)
result = @adapter.delete(key)
@cache.delete(key)
result
end
+ # Public
def set_add(key, value)
result = @adapter.set_add(key, value)
@cache.delete(key)
result
end
+ # Public
def set_delete(key, value)
result = @adapter.set_delete(key, value)
@cache.delete(key)
result
end
+ # Public
def set_members(key)
@cache.fetch(key) {
@cache[key] = @adapter.set_members(key)
}
end