Class: DiskStore::Reaper
- Inherits:
-
Object
- Object
- DiskStore::Reaper
- Includes:
- Celluloid
- 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.
Class Method Summary collapse
-
.spawn_for(path, opts = {}) ⇒ Object
Spawn exactly 1 reaper for each cache path.
Instance Method Summary collapse
-
#initialize(path, opts = {}) ⇒ Reaper
constructor
A new instance of Reaper.
- #set_eviction_strategy(strategy) ⇒ Object
- #start! ⇒ Object
Constructor Details
#initialize(path, opts = {}) ⇒ Reaper
Returns a new instance of Reaper.
28 29 30 31 32 33 |
# File 'lib/disk_store/reaper.rb', line 28 def initialize(path, opts = {}) @path = path @options = DEFAULT_OPTS.merge(opts) set_eviction_strategy(@options[:eviction_strategy]) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
26 27 28 |
# File 'lib/disk_store/reaper.rb', line 26 def path @path end |
Class Method Details
.spawn_for(path, opts = {}) ⇒ Object
Spawn exactly 1 reaper for each cache path
18 19 20 21 22 23 24 |
# File 'lib/disk_store/reaper.rb', line 18 def self.spawn_for(path, opts = {}) return Celluloid::Actor[path] if !Celluloid::Actor[path].nil? Reaper.supervise_as(path, path, opts) Celluloid::Actor[path].async.start! Celluloid::Actor[path] end |
Instance Method Details
#set_eviction_strategy(strategy) ⇒ Object
35 36 37 38 |
# File 'lib/disk_store/reaper.rb', line 35 def set_eviction_strategy(strategy) return if strategy.nil? self.class.send :prepend, DiskStore::Reaper.const_get(strategy) end |
#start! ⇒ Object
40 41 42 43 44 45 |
# File 'lib/disk_store/reaper.rb', line 40 def start! loop do perform_sweep! if needs_eviction? wait_for_next end end |