No commit activity in last 3 years
No release in over 3 years
Counter storage system for a concrete time window
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 1.2.0
= 0.10.0
= 0.9.2.2

Runtime

>= 0
 Project Readme

Time Window Drop Collector

System to keep record of an amount for a concrete duration.

With Time Window Drop Collector you can define a maximun time you want to keep the record.

You can also keep record for different keys.

How to use

Install

gem install time_window_drop_collector

Config

twdc =
  TimeWindowDropCollector.new do
    client <client>, <client_opts>     # underneeth client
    window <seconds>                   # in seconds
    slices <num of slices>             # one slice every minute
  end

These are the default values

twdc =
  TimeWindowDropCollector.new do
    client :memcache, "localhost:11211"     # underneeth client
    window 600                              # in seconds
    slices 10                               # one slice every minute
  end

Client

Can be:

  • :memcache
  • :redis
  • :rails
  • :mock

Use

twdc.drop( "id1" )
twdc.drop( "id1" )
twdc.drop( "id2" )
ts = twdc.drop( "id1", 4 )

twdc.count( "id1" )  # => 6
twdc.count( "id2" )  # => 1

twdc.pick( ts, "id1", 2)
twdc.count( "id1" )  # => 4

# after 10 minutes
twdc.count( "id1" )  # => 0

Cache clients wrappers

Now we have implementation for 3 diferent underneeth cache clients.

Memcache

It uses the Dalli Client for memcache.

twdc =
  TimeWindowDropCollector.new do
    client :memcache, "localhost:11211"
  end

Rails cache

It uses the Rails.cache accesible

twdc =
  TimeWindowDropCollector.new do
    client :rails_cache
  end

Redis

twdc =
  TimeWindowDropCollector.new do
    client :redis, { :host => "host", :port => "port" }
  end

Log

You can set the ENV_VAR TWDC_DEBUG and debug log will put to the stdout.