Module: SolidCache::Store::Expiry

Included in:
SolidCache::Store
Defined in:
lib/solid_cache/store/expiry.rb

Constant Summary collapse

EXPIRY_MULTIPLIER =

For every write that we do, we attempt to delete EXPIRY_MULTIPLIER times as many records. This ensures there is downward pressure on the cache size while there is valid data to delete

2

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#expires_per_writeObject (readonly)

Returns the value of attribute expires_per_write.



12
13
14
# File 'lib/solid_cache/store/expiry.rb', line 12

def expires_per_write
  @expires_per_write
end

#expiry_batch_sizeObject (readonly)

Returns the value of attribute expiry_batch_size.



12
13
14
# File 'lib/solid_cache/store/expiry.rb', line 12

def expiry_batch_size
  @expiry_batch_size
end

#expiry_methodObject (readonly)

Returns the value of attribute expiry_method.



12
13
14
# File 'lib/solid_cache/store/expiry.rb', line 12

def expiry_method
  @expiry_method
end

#expiry_queueObject (readonly)

Returns the value of attribute expiry_queue.



12
13
14
# File 'lib/solid_cache/store/expiry.rb', line 12

def expiry_queue
  @expiry_queue
end

#max_ageObject (readonly)

Returns the value of attribute max_age.



12
13
14
# File 'lib/solid_cache/store/expiry.rb', line 12

def max_age
  @max_age
end

#max_entriesObject (readonly)

Returns the value of attribute max_entries.



12
13
14
# File 'lib/solid_cache/store/expiry.rb', line 12

def max_entries
  @max_entries
end

#max_sizeObject (readonly)

Returns the value of attribute max_size.



12
13
14
# File 'lib/solid_cache/store/expiry.rb', line 12

def max_size
  @max_size
end

Instance Method Details

#initialize(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/solid_cache/store/expiry.rb', line 14

def initialize(options = {})
  super(options)
  @expiry_batch_size = options.fetch(:expiry_batch_size, 100)
  @expiry_method = options.fetch(:expiry_method, :thread)
  @expiry_queue = options.fetch(:expiry_queue, :default)
  @expires_per_write = (1 / expiry_batch_size.to_f) * EXPIRY_MULTIPLIER
  @max_age = options.fetch(:max_age, 2.weeks.to_i)
  @max_entries = options.fetch(:max_entries, nil)
  @max_size = options.fetch(:max_size, nil)

  raise ArgumentError, "Expiry method must be one of `:thread` or `:job`" unless [ :thread, :job ].include?(expiry_method)
end

#track_writes(count) ⇒ Object



27
28
29
# File 'lib/solid_cache/store/expiry.rb', line 27

def track_writes(count)
  expiry_batches(count).times { expire_later }
end