Class: Cache
- Inherits:
-
Object
- Object
- Cache
- Defined in:
- lib/cache.rb
Instance Method Summary collapse
- #contents ⇒ Object
- #expired? ⇒ Boolean
-
#initialize(source, fetchm, exp = 86400) ⇒ Cache
constructor
A new instance of Cache.
- #put(stuff) ⇒ Object
Constructor Details
#initialize(source, fetchm, exp = 86400) ⇒ Cache
Returns a new instance of Cache.
3 4 5 6 7 8 9 |
# File 'lib/cache.rb', line 3 def initialize(source, fetchm, exp=86400) @expiry = exp @timestamp = 0 @contents = [] @source = source @fetch = fetchm end |
Instance Method Details
#contents ⇒ Object
11 12 13 14 15 16 |
# File 'lib/cache.rb', line 11 def contents if expired? put(@source.send(@fetch)) end @contents end |
#expired? ⇒ Boolean
23 24 25 |
# File 'lib/cache.rb', line 23 def expired? (Time.now.utc.to_i - @timestamp) > @expiry end |
#put(stuff) ⇒ Object
18 19 20 21 |
# File 'lib/cache.rb', line 18 def put(stuff) @timestamp = Time.now.utc.to_i @contents = stuff end |