Created
December 1, 2008 20:59
-
-
Save jsierles/30843 to your computer and use it in GitHub Desktop.
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
require "timeout" | |
class MemCache | |
alias_method :old_get, :get | |
alias_method :old_set, :set | |
alias_method :old_incr, :incr | |
alias_method :old_add, :add | |
alias_method :old_delete, :delete | |
alias_method :old_get_multi, :get_multi | |
def get(key, raw = false, timeout = 1.0) | |
Timeout::timeout(timeout) do | |
old_get(key, raw) | |
end | |
rescue Timeout::Error | |
nil | |
end | |
end | |
def set(key, value, expiry = 0, raw = false, timeout = 1.0) | |
Timeout::timeout(timeout) do | |
old_set(key, value, expiry, raw) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment