mirror of
https://github.com/discourse/discourse.git
synced 2025-04-16 17:40:15 +08:00

implemented an ActiveSupport::Cache::Store for our internal use. * allows for expire by family * works correctly in multisite * namespaced correctly Removed redis-rails from the project, no longer needed
71 lines
1.4 KiB
Ruby
71 lines
1.4 KiB
Ruby
require 'spec_helper'
|
|
require 'cache'
|
|
|
|
describe Cache do
|
|
|
|
let :cache do
|
|
Cache.new
|
|
end
|
|
|
|
it "can be cleared" do
|
|
cache.write("hello0", "world")
|
|
cache.write("hello1", "world")
|
|
cache.clear
|
|
|
|
cache.read("hello0").should be_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")
|
|
|
|
cache.fetch("key").should be_nil
|
|
cache.fetch("key2").should be_nil
|
|
|
|
end
|
|
|
|
it "can delete correctly" do
|
|
cache.fetch("key", expires_in: 1.minute) do
|
|
"test"
|
|
end
|
|
|
|
cache.delete("key")
|
|
cache.fetch("key").should be_nil
|
|
end
|
|
|
|
it "can store with expiry correctly" do
|
|
key = cache.namespaced_key("key")
|
|
$redis.expects(:get).with(key).returns nil
|
|
$redis.expects(:setex).with(key, 60 , "bob")
|
|
|
|
r = cache.fetch("key", expires_in: 1.minute) do
|
|
"bob"
|
|
end
|
|
r.should == "bob"
|
|
end
|
|
|
|
it "can store and fetch correctly" do
|
|
key = cache.namespaced_key("key")
|
|
$redis.expects(:get).with(key).returns nil
|
|
$redis.expects(:set).with(key, "bob")
|
|
|
|
r = cache.fetch "key" do
|
|
"bob"
|
|
end
|
|
r.should == "bob"
|
|
end
|
|
|
|
it "can fetch existing correctly" do
|
|
key = cache.namespaced_key("key")
|
|
|
|
$redis.expects(:get).with(key).returns "bill"
|
|
|
|
r = cache.fetch "key" do
|
|
"bob"
|
|
end
|
|
r.should == "bill"
|
|
end
|
|
end
|