Skip to content
Browse files

redis cache: prefixing cache keys with "support-"

  • Loading branch information...
1 parent 2a33df5 commit 1241285ce2860ba670e41e994a1ffef4d2766991 @benilovj benilovj committed
Showing with 9 additions and 5 deletions.
  1. +9 −5 app/models/user.rb
View
14 app/models/user.rb
@@ -7,12 +7,12 @@ def self.attr_accessible(*args)
include GDS::SSO::User
def self.find_by_uid(uid)
- auth_hash = Rails.cache.fetch(uid)
+ auth_hash = Rails.cache.fetch(prefixed_key(uid))
auth_hash ? User.new(auth_hash) : nil
end
def self.create!(auth_hash, options={})
- Rails.cache.write(auth_hash["uid"], auth_hash)
+ Rails.cache.write(prefixed_key(auth_hash["uid"]), auth_hash)
User.new(auth_hash)
end
@@ -22,9 +22,9 @@ def remotely_signed_out?
def update_attribute(key, value)
if uid
- old_attributes = Rails.cache.fetch(uid)
+ old_attributes = Rails.cache.fetch(self.class.prefixed_key(uid))
new_attributes = old_attributes.merge(key => value)
- Rails.cache.write(new_attributes["uid"], new_attributes)
+ Rails.cache.write(self.class.prefixed_key(new_attributes["uid"]), new_attributes)
end
send("#{key}=", value)
end
@@ -33,6 +33,10 @@ def update_attributes(params, hash)
params.each do |key, value|
send("#{key}=", value)
end
- Rails.cache.write(params["uid"], params)
+ Rails.cache.write(self.class.prefixed_key(params["uid"]), params)
+ end
+
+ def self.prefixed_key(key)
+ "support-#{key}"
end
end

0 comments on commit 1241285

Please sign in to comment.
Something went wrong with that request. Please try again.