Skip to content

Instantly share code, notes, and snippets.

@jsierles
Created December 1, 2008 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsierles/30843 to your computer and use it in GitHub Desktop.
Save jsierles/30843 to your computer and use it in GitHub Desktop.
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