FIX: emoji cache could get corrupt

FEATURE: enforce 1 day expiry by default on discourse cache

remove family expiry concept as the implementation was fragile
This commit is contained in:
Sam
2015-02-19 16:58:05 +11:00
parent 8da38cda81
commit 103d42a9d9
3 changed files with 30 additions and 51 deletions

View File

@ -19,24 +19,15 @@ describe Cache do
end
it "can be cleared" do
$redis.set("boo", "boo")
cache.write("hello0", "world")
cache.write("hello1", "world")
cache.clear
expect($redis.get("boo")).to eq("boo")
expect(cache.read("hello0")).to eq(nil)
end
it "can delete by family" do
cache.write("key2", "test", family: "my_family")
cache.write("key", "test", expires_in: 1.minute, family: "my_family")
cache.delete_by_family("my_family")
expect(cache.fetch("key")).to eq(nil)
expect(cache.fetch("key2")).to eq(nil)
end
it "can delete correctly" do
cache.fetch("key", expires_in: 1.minute) do
"test"
@ -46,16 +37,23 @@ describe Cache do
expect(cache.fetch("key")).to eq(nil)
end
#TODO yuck on this mock
it "calls setex in redis" do
cache.delete("key")
cache.delete("bla")
key = cache.namespaced_key("key")
$redis.expects(:setex).with(key, 60 , Marshal.dump("bob"))
cache.fetch("key", expires_in: 1.minute) do
"bob"
end
expect($redis.ttl(key)).to be_within(2.seconds).of(1.minute)
# we always expire withing a day
cache.fetch("bla"){ "hi" }
key = cache.namespaced_key("bla")
expect($redis.ttl(key)).to be_within(2.seconds).of(1.day)
end
it "can store and fetch correctly" do