-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: support for ActiveSupport::MemCacheStore #153
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
397a7ce
feature: support for ActiveSupport::MemCacheStore
faa0638
fix: Do not attempt to process Memcache clients with DalliProxy
d880bd8
fix: workaround MemCacheClient + MemCache backend by using a dedicate…
297ef4a
Merge branch 'master' of github.com:kickstarter/rack-attack
32df84d
fix: check whether client class is defined before checking client itself
ba9f2c3
fix: move dev depencies to gemspec
8d124d8
refactor unwieldy Rack::Attack::StoreProxy.build method
c34bace
style: remove extraneous whitespace
585d1fd
Revert "refactor unwieldy Rack::Attack::StoreProxy.build method"
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Rack | ||
class Attack | ||
module StoreProxy | ||
class MemCacheProxy < SimpleDelegator | ||
def self.handle?(store) | ||
defined?(::MemCache) && store.is_a?(::MemCache) | ||
end | ||
|
||
def initialize(store) | ||
super(store) | ||
stub_with_if_missing | ||
end | ||
|
||
def read(key) | ||
# Second argument: reading raw value | ||
get(key, true) | ||
rescue MemCache::MemCacheError | ||
end | ||
|
||
def write(key, value, options={}) | ||
# Third argument: writing raw value | ||
set(key, value, options.fetch(:expires_in, 0), true) | ||
rescue MemCache::MemCacheError | ||
end | ||
|
||
def increment(key, amount, options={}) | ||
incr(key, amount) | ||
rescue MemCache::MemCacheError | ||
end | ||
|
||
def delete(key, options={}) | ||
with do |client| | ||
client.delete(key) | ||
end | ||
rescue MemCache::MemCacheError | ||
end | ||
|
||
private | ||
|
||
def stub_with_if_missing | ||
unless __getobj__.respond_to?(:with) | ||
class << self | ||
def with; yield __getobj__; end | ||
end | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add
memcache-client
as a development dependency instead?This file is auto-generated from
Appraisals
file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've addressed that. Didn't know about
appraisal
, very interesting stuff!I've also refactored the
Rack::Attack::StoreProxy.build
method, which was getting too cluttered in my opinion (but I could move that to a separate PR if you think it's necessary).