Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. require "timeout"
  2.  
  3. class MemCache
  4. alias_method :old_get, :get
  5. alias_method :old_set, :set
  6. alias_method :old_incr, :incr
  7. alias_method :old_add, :add
  8. alias_method :old_delete, :delete
  9. alias_method :old_get_multi, :get_multi
  10.  
  11.  
  12. def get(key, raw = false, timeout = 1.0)
  13. Timeout::timeout(timeout) do
  14. old_get(key, raw)
  15. end
  16. rescue Timeout::Error
  17. nil
  18. end
  19. end
  20.  
  21. def set(key, value, expiry = 0, raw = false, timeout = 1.0)
  22. Timeout::timeout(timeout) do
  23. old_set(key, value, expiry, raw)
  24. end
  25. end
Add Comment
Please, Sign In to add comment