class Cassie::Statements::Statement::Preparation::Cache

Attributes

data[R]

Public Class Methods

new() click to toggle source
# File lib/cassie/statements/statement/preparation/cache.rb, line 6
def initialize
  clear
  @monitor = Monitor.new
end

Public Instance Methods

clear() click to toggle source
# File lib/cassie/statements/statement/preparation/cache.rb, line 25
def clear
  @data = {}
end
close() click to toggle source
# File lib/cassie/statements/statement/preparation/cache.rb, line 28
def close
  clear
end
fetch(key) { || ... } click to toggle source
# File lib/cassie/statements/statement/preparation/cache.rb, line 21
def fetch(key)
  return read(key) if data.has_key?(key)
  write(key, yield) if block_given?
end
read(key) click to toggle source
# File lib/cassie/statements/statement/preparation/cache.rb, line 16
def read(key)
  synchronize do
    data[key]
  end
end
write(key, value) click to toggle source
# File lib/cassie/statements/statement/preparation/cache.rb, line 11
def write(key, value)
  synchronize do
    @data[key] = value
  end
end

Private Instance Methods

synchronize(&block) click to toggle source
# File lib/cassie/statements/statement/preparation/cache.rb, line 34
def synchronize(&block)
  @monitor.synchronize(&block)
end