Class: Pa::Cache
- Inherits:
-
Object
- Object
- Pa::Cache
- Defined in:
- lib/pa/cache.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #fetch(key, time, &block) ⇒ Object
-
#initialize(path) ⇒ Cache
constructor
A new instance of Cache.
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
#path ⇒ Object (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 |