# Matador [![Build Status](https://travis-ci.org/StevenJL/matador.svg?branch=master)](https://travis-ci.org/StevenJL/matador) Stop cache expiration triggered [thundering herd](https://en.wikipedia.org/wiki/Thundering_herd_problem) problems with Matador. Currently works with redis. ## Installation Add this line to your application's Gemfile: gem 'matador' And then execute: $ bundle Or install it yourself as: $ gem install matador ## Usage Set your cache service object (currently only supports redis) ```ruby require "matador" require "redis" $redis = Redis.new(host: "127.0.0.1", port: "16379") Matador.cache_store = $redis ``` Caching with an expiration is susceptible to a thundering herd in high traffic situations: ```ruby data = time_consuming_operation(...) $redis.set("some_key", data) $redis.expire("some_key", 120) ``` Wrap it in matador. When the cache expires after 2 minutes, the first request goes through to generate the new cache. While the new cache is being built (next 10 seconds), all other requests are served the stale cache. ```ruby Matador.fetch("some_key", :ttl => 120, :therd_ttl => 10) do time_consuming_operation end ``` ## TO DO 1. Integrate with Memcache ## Contributing 1. Fork it ( http://github.com//matador/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request