From b53df6dd4d38f079f294038a9bc75766b08401c9 Mon Sep 17 00:00:00 2001
From: danielgrippi <danielgrippi@gmail.com>
Date: Mon, 7 Nov 2011 11:28:24 -0800
Subject: [PATCH] repopulating the redis cache should clear the entire set
 first

---
 lib/diaspora/redis_cache.rb           |  5 +++++
 spec/lib/diaspora/redis_cache_spec.rb | 15 ++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/lib/diaspora/redis_cache.rb b/lib/diaspora/redis_cache.rb
index bacb3f1321..8f5ceb6728 100644
--- a/lib/diaspora/redis_cache.rb
+++ b/lib/diaspora/redis_cache.rb
@@ -39,9 +39,14 @@ class RedisCache
   end
 
   def repopulate!(opts = {})
+    self.purge!
     self.populate!(opts) && self.trim!
   end
 
+  def purge!
+    self.redis.del(set_key)
+  end
+
   def populate!(opts = {})
     # user executes query and gets back hashes
     opts.merge!({
diff --git a/spec/lib/diaspora/redis_cache_spec.rb b/spec/lib/diaspora/redis_cache_spec.rb
index 302ef3a817..27dd9d6dd4 100644
--- a/spec/lib/diaspora/redis_cache_spec.rb
+++ b/spec/lib/diaspora/redis_cache_spec.rb
@@ -63,7 +63,7 @@ describe RedisCache do
       @cache.ensure_populated!
     end
 
-    it 'clears and poplulates if the cache is not populated' do
+    it 'calls #repopulate' do
       opts = {:here_is => "something"}
       @cache.stub(:cache_exists?).and_return(false)
       @cache.should_receive(:repopulate!).with(opts)
@@ -73,6 +73,11 @@ describe RedisCache do
   end
 
   describe "#repopulate!" do
+    it 'calls #purge!' do
+      @cache.should_receive(:purge!)
+      @cache.repopulate!
+    end
+
     it 'populates' do
       opts = {:here_is => "something"}
       @cache.stub(:trim!).and_return(true)
@@ -87,6 +92,14 @@ describe RedisCache do
     end
   end
 
+  describe '#purge!' do
+    it 'clears the set in redis' do
+      @cache.stub(:redis).and_return(@redis)
+      @redis.should_receive(:del).with(@cache.send(:set_key))
+      @cache.purge!
+    end
+  end
+
   describe "#populate!" do
     it 'queries the db with the visible post sql string' do
       sql = "long_sql"
-- 
GitLab