0

I'm trying to understand how rack-attack uses memcached to throttle connections.

As far as I can tell there's no easy way to manage lists in memcached, and no way to search keys by prefix. Yet rack-attack is somehow keeping a list count within cache, but I'm staring at the source code and can't figure out how it works?

https://github.com/kickstarter/rack-attack/blob/master/lib/rack/attack/throttle.rb https://github.com/kickstarter/rack-attack/blob/master/lib/rack/attack/cache.rb

Community
  • 1
  • 1
Yarin
  • 173,523
  • 149
  • 402
  • 512

1 Answers1

1

It's possible to emulate namespacing, tagging and indexing with memcached, which allows you to work around many limitations (in your case you could maintain prefixes as tags). This article has some good ideas, and the memcached docs have some neat tricks too.

Synchro
  • 35,538
  • 15
  • 81
  • 104
  • Thanks- I ended up just replacing memcached with redis, which supports lists natively, instead of trying to mess with these work arounds – Yarin Feb 15 '14 at 14:57