class Sidekiq::Throttler::Storage::Memory
Stores job executions in a Hash of Arrays.
Public Class Methods
new()
click to toggle source
# File lib/sidekiq/throttler/storage/memory.rb, line 9 def initialize @hash = Hash.new { |hash, key| hash[key] = [] } end
Public Instance Methods
append(key, time)
click to toggle source
Add a new entry to the hash.
@param [String] key
The key to append to
@param [Time] time
The time to insert
# File lib/sidekiq/throttler/storage/memory.rb, line 45 def append(key, time) @hash[key] << time end
count(key)
click to toggle source
Number of executions for key
.
@param [String] key
Key to fetch count for
@return [Fixnum]
Execution count
# File lib/sidekiq/throttler/storage/memory.rb, line 21 def count(key) @hash[key].length end
prune(key, cutoff)
click to toggle source
Remove entries older than cutoff
.
@param [String] key
The key to prune
@param [Time] cutoff
Oldest allowable time
# File lib/sidekiq/throttler/storage/memory.rb, line 33 def prune(key, cutoff) @hash[key].reject! { |time| time <= cutoff } end
reset()
click to toggle source
# File lib/sidekiq/throttler/storage/memory.rb, line 49 def reset @hash.clear end