README.rdoc in prop-0.5.1 vs README.rdoc in prop-0.6.0
- old
+ new
@@ -13,13 +13,13 @@
Rails.cache.write(key, value)
end
You can choose to rely on a database or Moneta or Redis or whatever you'd like to use for transient storage. Prop does not do any sort of clean up of its key space, so you would have to implement that manually should you be using anything but an LRU cache.
-Once the read and write operations are defined, you can optionally define some preconfigured default thresholds. If for example, you want to have a threshold on accepted emails per hour from a given user, you could define a threshold and interval (in seconds) for this like so:
+Once the read and write operations are defined, you can optionally define thresholds. If for example, you want to have a threshold on accepted emails per hour from a given user, you could define a threshold and interval (in seconds) for this like so:
- Prop.defaults(:mails_per_hour, :threshold => 100, :interval => 1.hour)
+ Prop.configure(:mails_per_hour, :threshold => 100, :interval => 1.hour)
You can now put the throttle to work with this values, by passing the "handle" to the respective methods in Prop:
# Throws Prop::RateLimitExceededError if the threshold/interval has been reached
Prop.throttle!(:mails_per_hour)
@@ -48,11 +48,11 @@
THROTTLE_MESSAGES = Hash.new("Throttle exceeded")
THROTTLE_MESSAGES[:login] = "Too many invalid login attempts. Try again later."
rescue_from Prop::RateLimitExceededError do |exception|
- render :status => 403, :message => THROTTLE_MESSAGES[exception.handle]
+ render :status => 403, :message => I18n.t(THROTTLE_MESSAGES[exception.handle])
end
You can chose to override the threshold for a given key:
Prop.throttle!(:mails_per_hour, mail.from, :threshold => account.mail_throttle_threshold)
@@ -70,17 +70,14 @@
== How it works
Prop uses the interval to define a window of time using simple div arithmetic. This means that it's a worst case throttle that will allow up to 2 times the specified requests within the specified interval.
== Note on Patches/Pull Requests
-
+
* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.
-== Copyright
-
-Copyright (c) 2010 Morten Primdahl. See LICENSE for details.