Created
May 18, 2011 00:15
-
-
Save statianzo/977743 to your computer and use it in GitHub Desktop.
[PATCH] Memcached store handles Memcached::NotFound and Memcached::NotStored
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
lib/openid/store/memcache.rb | 28 ++++++++++++++++++++-------- | |
1 files changed, 20 insertions(+), 8 deletions(-) | |
diff --git a/lib/openid/store/memcache.rb b/lib/openid/store/memcache.rb | |
index bb4b106..8d6242b 100644 | |
--- a/lib/openid/store/memcache.rb | |
+++ b/lib/openid/store/memcache.rb | |
@@ -30,10 +30,14 @@ module OpenID | |
# the one matching association is expired. (Is allowed to GC expired | |
# associations when found.) | |
def get_association(server_url, handle=nil) | |
- serialized = @cache_client.get(assoc_key(server_url, handle)) | |
- if serialized | |
- return deserialize(serialized) | |
- else | |
+ begin | |
+ serialized = @cache_client.get(assoc_key(server_url, handle)) | |
+ if serialized | |
+ return deserialize(serialized) | |
+ else | |
+ return nil | |
+ end | |
+ rescue Memcached::NotFound | |
return nil | |
end | |
end | |
@@ -62,8 +66,12 @@ module OpenID | |
return false if (timestamp - Time.now.to_i).abs > Nonce.skew | |
ts = timestamp.to_s # base 10 seconds since epoch | |
nonce_key = key_prefix + 'N' + server_url + '|' + ts + '|' + salt | |
- result = @cache_client.add(nonce_key, '', expiry(Nonce.skew + 5)) | |
- return !!(result =~ /^STORED/) | |
+ begin | |
+ result = @cache_client.add(nonce_key, '', expiry(Nonce.skew + 5)) | |
+ return result.nil? || !!(result =~ /^STORED/) | |
+ rescue Memcached::NotStored | |
+ return false | |
+ end | |
end | |
def assoc_key(server_url, assoc_handle=nil) | |
@@ -86,8 +94,12 @@ module OpenID | |
protected | |
def delete(key) | |
- result = @cache_client.delete(key) | |
- return !!(result =~ /^DELETED/) | |
+ begin | |
+ result = @cache_client.delete(key) | |
+ return result.nil? || !!(result =~ /^DELETED/) | |
+ rescue Memcached::NotFound | |
+ return false | |
+ end | |
end | |
def serialize(assoc) | |
-- | |
1.7.4.msysgit.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment