Class: FastRuby::Cache

Inherits:
Object show all
Includes:
FileUtils
Defined in:
lib/fastruby/cache/cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_path) ⇒ Cache

Returns a new instance of Cache.



34
35
36
37
# File 'lib/fastruby/cache/cache.rb', line 34

def initialize(base_path)
  @base_path = base_path
  create_dir_if_not_exists(@base_path)
end

Instance Method Details

#execute(obj, param) ⇒ Object



60
61
62
63
64
65
# File 'lib/fastruby/cache/cache.rb', line 60

def execute(obj, param)
  @proc_hash = Hash.new unless @proc_hash
  if @proc_hash[obj]
    @proc_hash[obj].call(param)
  end
end

#hash_snippet(snippet, addition) ⇒ Object



39
40
41
# File 'lib/fastruby/cache/cache.rb', line 39

def hash_snippet(snippet, addition)
  Digest::SHA1.hexdigest(snippet + addition)
end

#insert(hash, path) ⇒ Object



43
44
45
46
47
# File 'lib/fastruby/cache/cache.rb', line 43

def insert(hash,path)
  create_hash_dir(hash)
  dest = hash_dir(hash)
  cp_r path, dest
end

#register_proc(obj, value) ⇒ Object



55
56
57
58
# File 'lib/fastruby/cache/cache.rb', line 55

def register_proc(obj, value)
  @proc_hash = Hash.new unless @proc_hash
  @proc_hash[obj] = value
end

#retrieve(hash) ⇒ Object



49
50
51
52
53
# File 'lib/fastruby/cache/cache.rb', line 49

def retrieve(hash)
  create_hash_dir(hash)
  dest = hash_dir(hash)
  Dir[dest + "*.so"]
end