Permalink
Browse files

using Rails mechanism for namespacing cache keys

  • Loading branch information...
1 parent c9e7c92 commit b89864419dca4b1199d7c42ca372aceefceab720 @benilovj benilovj committed Mar 13, 2013
Showing with 10 additions and 2 deletions.
  1. +1 −1 app/models/user.rb
  2. +5 −1 config/application.rb
  3. +4 −0 test/unit/models/user_test.rb
View
@@ -37,6 +37,6 @@ def update_attributes(params, hash)
end
def self.prefixed_key(key)
- "support-#{key}"
+ "users-#{key}"
end
end
View
@@ -49,7 +49,11 @@ class Application < Rails::Application
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
- config.cache_store = :redis_store, "redis://#{ENV['REDIS_HOST'] || 'localhost:6379'}", { expires_in: 24.hours }
+ config.cache_store = [
+ :redis_store,
+ "redis://#{ENV['REDIS_HOST'] || 'localhost:6379'}",
+ { expires_in: 24.hours, namespace: "support-#{Rails.env}" }
+ ]
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
@@ -5,6 +5,10 @@ def setup
Rails.cache.clear
end
+ def teardown
+ Rails.cache.clear
+ end
+
should "support persistent creation and retrieval" do
assert_nil User.find_by_uid("12345")
user = User.create!("uid" => "12345", "name" => "A", "email" => "a@b.com")

0 comments on commit b898644

Please sign in to comment.