-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from elhu/master
feature: support for ActiveSupport::MemCacheStore
- Loading branch information
Showing
5 changed files
with
68 additions
and
6 deletions.
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
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
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