Class: Pa::Cache

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Cache

Returns a new instance of Cache.



7
8
9
# File 'lib/pa/cache.rb', line 7

def initialize(path)
  @path = File.join(path, 'cache')
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/pa/cache.rb', line 5

def path
  @path
end

Instance Method Details

#fetch(key, time, &block) ⇒ Object



11
12
13
14
# File 'lib/pa/cache.rb', line 11

def fetch(key, time, &block)
  write(key, (yield block)) if !exists?(key) || expired?(key, time)
  read key
end