From 7208f28ebe5be0e860749a86315653752ae7b131 Mon Sep 17 00:00:00 2001 From: Guillaume DOTT Date: Sun, 20 Jan 2013 01:12:09 +0100 Subject: [PATCH] Use Rails.cache.fetch instead of read/write --- .../request_suspicious_ips_protection.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/project_honeypot_rails/request_suspicious_ips_protection.rb b/lib/project_honeypot_rails/request_suspicious_ips_protection.rb index 97efcc7..6a32395 100644 --- a/lib/project_honeypot_rails/request_suspicious_ips_protection.rb +++ b/lib/project_honeypot_rails/request_suspicious_ips_protection.rb @@ -14,11 +14,8 @@ module ProjectHoneypotRails ip_address = request.remote_ip key = "httpbl_#{ip_address}" - if Rails.cache.exist?(key) - safe = Rails.cache.read(key) - else - safe = ::ProjectHoneypot.lookup(ip_address).safe? - Rails.cache.write(key, safe, expires_in: 6.hours) + safe = Rails.cache.fetch(key, expires_in: 6.hours) do + ::ProjectHoneypot.lookup(ip_address).safe? end handle_unverified_request unless safe