Module: SolidCache::Cluster::Expiry

Included in:
SolidCache::Cluster
Defined in:
lib/solid_cache/cluster/expiry.rb

Defined Under Namespace

Classes: Counter

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

1.25

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#expire_everyObject (readonly)

Returns the value of attribute expire_every.



10
11
12
# File 'lib/solid_cache/cluster/expiry.rb', line 10

def expire_every
  @expire_every
end

#expiry_batch_sizeObject (readonly)

Returns the value of attribute expiry_batch_size.



10
11
12
# File 'lib/solid_cache/cluster/expiry.rb', line 10

def expiry_batch_size
  @expiry_batch_size
end

#expiry_methodObject (readonly)

Returns the value of attribute expiry_method.



10
11
12
# File 'lib/solid_cache/cluster/expiry.rb', line 10

def expiry_method
  @expiry_method
end

#max_ageObject (readonly)

Returns the value of attribute max_age.



10
11
12
# File 'lib/solid_cache/cluster/expiry.rb', line 10

def max_age
  @max_age
end

#max_entriesObject (readonly)

Returns the value of attribute max_entries.



10
11
12
# File 'lib/solid_cache/cluster/expiry.rb', line 10

def max_entries
  @max_entries
end

Instance Method Details

#initialize(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
# File 'lib/solid_cache/cluster/expiry.rb', line 12

def initialize(options = {})
  super(options)
  @expiry_batch_size = options.fetch(:expiry_batch_size, 100)
  @expiry_method = options.fetch(:expiry_method, :thread)
  @expire_every = [ (expiry_batch_size / EXPIRY_MULTIPLIER).floor, 1 ].max
  @max_age = options.fetch(:max_age, 2.weeks.to_i)
  @max_entries = options.fetch(:max_entries, nil)

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

#track_writes(count) ⇒ Object



23
24
25
# File 'lib/solid_cache/cluster/expiry.rb', line 23

def track_writes(count)
  expire_later if expiry_counter.count(count)
end