Class: DiskStore::Reaper
- Inherits:
-
Object
- Object
- DiskStore::Reaper
- Defined in:
- lib/disk_store/reaper.rb,
lib/disk_store/eviction_strategies/lru.rb
Defined Under Namespace
Modules: LRU
Constant Summary collapse
- DEFAULT_OPTS =
{ cache_size: 1073741824, # 1 gigabyte reaper_interval: 10, # seconds, eviction_strategy: nil }
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Class Method Summary collapse
-
.kill_all! ⇒ Object
Mostly useful for testing purposes.
-
.spawn_for(path, opts = {}) ⇒ Object
Spawn exactly 1 reaper for each cache path.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(path, opts = {}) ⇒ Reaper
constructor
A new instance of Reaper.
- #running? ⇒ Boolean
- #set_eviction_strategy(strategy) ⇒ Object
- #spawn! ⇒ Object
Constructor Details
#initialize(path, opts = {}) ⇒ Reaper
Returns a new instance of Reaper.
32 33 34 35 36 37 38 |
# File 'lib/disk_store/reaper.rb', line 32 def initialize(path, opts = {}) @path = path @options = DEFAULT_OPTS.merge(opts) @thread = nil set_eviction_strategy(@options[:eviction_strategy]) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
30 31 32 |
# File 'lib/disk_store/reaper.rb', line 30 def path @path end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
30 31 32 |
# File 'lib/disk_store/reaper.rb', line 30 def thread @thread end |
Class Method Details
.kill_all! ⇒ Object
Mostly useful for testing purposes
25 26 27 28 |
# File 'lib/disk_store/reaper.rb', line 25 def self.kill_all! @reapers.each { |path, reaper| reaper.thread.kill } @reapers = {} end |
.spawn_for(path, opts = {}) ⇒ Object
Spawn exactly 1 reaper for each cache path
14 15 16 17 18 19 20 21 22 |
# File 'lib/disk_store/reaper.rb', line 14 def self.spawn_for(path, opts = {}) return @reapers[path] if @reapers.has_key?(path) reaper = Reaper.new(path, opts) reaper.spawn! @reapers[path] = reaper reaper end |
Instance Method Details
#alive? ⇒ Boolean
54 55 56 |
# File 'lib/disk_store/reaper.rb', line 54 def alive? @thread && @thread.alive? end |
#running? ⇒ Boolean
58 59 60 |
# File 'lib/disk_store/reaper.rb', line 58 def running? @thread && !@thread.stop? end |
#set_eviction_strategy(strategy) ⇒ Object
40 41 42 43 |
# File 'lib/disk_store/reaper.rb', line 40 def set_eviction_strategy(strategy) return if strategy.nil? self.class.send :prepend, DiskStore::Reaper.const_get(strategy) end |
#spawn! ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/disk_store/reaper.rb', line 45 def spawn! @thread = Thread.new do loop do perform_sweep! if needs_eviction? wait_for_next end end end |