repopulating the redis cache should clear the entire set first

This commit is contained in:
danielgrippi 2011-11-07 11:28:24 -08:00
parent fd76cfd4c5
commit b53df6dd4d
2 changed files with 19 additions and 1 deletions

View file

@ -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!({

View file

@ -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"