Class: DpStmMap::CurrentValues

Inherits:
Object
  • Object
show all
Defined in:
lib/dp_stm_map/Manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(current_values_dir) ⇒ CurrentValues

Returns a new instance of CurrentValues.



123
124
125
126
127
# 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

Instance Method Details

#[](k) ⇒ Object



133
134
135
136
137
# 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) ⇒ Object



139
140
141
142
143
144
145
146
# 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) ⇒ Object



129
130
131
# File 'lib/dp_stm_map/Manager.rb', line 129

def file_name key
  "#{@current_values_dir}/#{key}"
end