Class: Proc

Inherits:
Object
  • Object
show all
Defined in:
lib/proc-cache.rb

Instance Method Summary collapse

Instance Method Details

#cache!(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/proc-cache.rb', line 5

def cache!(options={})
  cache_path = make_cache_path
  @logger = Logger.new(nil)

  cache_path = options[:cache_path] if options[:cache_path]
  expires = options[:expires] if options[:expires]
  @logger = options[:logger] if options[:logger]

  if File.exist? cache_path
    @logger.info "cache file found: #{cache_path}"
    return use_cache(cache_path, expires)
  else
    @logger.info "cache file not found, generating cache"
    data = self.call
    write_cache(cache_path, data)
    return data
  end
end