Class: Scrappy::Cache
- Inherits:
-
Hash
- Object
- Hash
- Scrappy::Cache
- Includes:
- MonitorMixin
- Defined in:
- lib/scrappy/agent/cache.rb
Constant Summary collapse
- MAX_ELEMENTS =
100
Instance Method Summary collapse
Instance Method Details
#[](key) ⇒ Object
36 37 38 |
# File 'lib/scrappy/agent/cache.rb', line 36 def [] key synchronize { super } end |
#[]=(key, value) ⇒ Object
32 33 34 |
# File 'lib/scrappy/agent/cache.rb', line 32 def []= key, value synchronize { super } end |
#expire!(timeout) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/scrappy/agent/cache.rb', line 24 def expire! timeout synchronize do keys.each { |key| delete(key) if Time.now.to_i - self[key][:time].to_i > timeout } sort_by { |key, value| value[:time].to_i }[0...size-MAX_ELEMENTS].each { |key, value| delete key } if size > MAX_ELEMENTS self end end |