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, *params) ⇒ Object



64
65
66
67
68
69
# File 'lib/fastruby/cache/cache.rb', line 64

def execute(obj, *params)
  @proc_hash = Hash.new unless @proc_hash
  if @proc_hash[obj]
    @proc_hash[obj].call(*params)
  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
48
49
# File 'lib/fastruby/cache/cache.rb', line 43

def insert(hash,path)
  unless ENV['FASTRUBY_NO_CACHE'] == '1'
    create_hash_dir(hash)
    dest = hash_dir(hash)
    cp_r path, dest
  end
end

#register_proc(obj, value) ⇒ Object



59
60
61
62
# File 'lib/fastruby/cache/cache.rb', line 59

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

#retrieve(hash) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/fastruby/cache/cache.rb', line 51

def retrieve(hash)
  return [] if ENV['FASTRUBY_NO_CACHE'] == '1'
  
  create_hash_dir(hash)
  dest = hash_dir(hash)
  Dir[dest + "*.so"]
end