Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Counter storage system for a concrete time window

This branch is 37 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.rvmrc.example
.travis.yml
Gemfile
README.md
Rakefile
time_window_drop_collector.gemspec

README.md

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

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

Use

twdc.drop( "id1" )
twdc.drop( "id1" )
twdc.drop( "id2" )
twdc.drop( ["id1", "id2"] )

twdc.count( "id1" )  # => 3

# 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

At the moment this wrapper does not support auto-key-clean so the stored keys will be there until anyone delete them.

Something went wrong with that request. Please try again.