class DpStmMap::CurrentValues

Public Class Methods

new(current_values_dir) click to toggle source
# File lib/dp_stm_map/Manager.rb, line 123
def initialize current_values_dir
  @current_values_dir=current_values_dir
  FileUtils.mkdir_p(current_values_dir) unless File.exist?(current_values_dir)
  @cache=ThreadSafeLru::LruCache.new 9000
end

Public Instance Methods

[](k) click to toggle source
# File lib/dp_stm_map/Manager.rb, line 133
def [] k
  @cache.get(k) do |key|
    File.exist?(file_name(key)) ? File.open(file_name(key),"r"){|f| f.read()} : nil
  end
end
[]=(key, value) click to toggle source
# File lib/dp_stm_map/Manager.rb, line 139
def []= key, value
  if value
    File.open(file_name(key),"w"){|f| f.write(value)}
  else
    File.unlink file_name(key) if File.exist? file_name(key)
  end
  @cache.drop(key)
end
file_name(key) click to toggle source
# File lib/dp_stm_map/Manager.rb, line 129
def file_name key
  "#{@current_values_dir}/#{key}"
end