BUGFIX: redis-rails has always been a problem child
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
This commit is contained in:
parent
5f6836bf13
commit
b703d8c77a
8 changed files with 107 additions and 86 deletions
|
@ -7,23 +7,27 @@ describe Cache do
|
|||
Cache.new
|
||||
end
|
||||
|
||||
it "can delete by family" do
|
||||
cache.fetch("key2", family: "my_family") do
|
||||
"test"
|
||||
end
|
||||
it "can be cleared" do
|
||||
cache.write("hello0", "world")
|
||||
cache.write("hello1", "world")
|
||||
cache.clear
|
||||
|
||||
cache.fetch("key", expires_in: 1.minute, family: "my_family") do
|
||||
"test"
|
||||
end
|
||||
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
|
||||
r = cache.fetch("key", expires_in: 1.minute) do
|
||||
cache.fetch("key", expires_in: 1.minute) do
|
||||
"test"
|
||||
end
|
||||
|
||||
|
@ -32,8 +36,9 @@ describe Cache do
|
|||
end
|
||||
|
||||
it "can store with expiry correctly" do
|
||||
$redis.expects(:get).with("key").returns nil
|
||||
$redis.expects(:setex).with("key", 60 , "bob")
|
||||
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"
|
||||
|
@ -42,8 +47,9 @@ describe Cache do
|
|||
end
|
||||
|
||||
it "can store and fetch correctly" do
|
||||
$redis.expects(:get).with("key").returns nil
|
||||
$redis.expects(:set).with("key", "bob")
|
||||
key = cache.namespaced_key("key")
|
||||
$redis.expects(:get).with(key).returns nil
|
||||
$redis.expects(:set).with(key, "bob")
|
||||
|
||||
r = cache.fetch "key" do
|
||||
"bob"
|
||||
|
@ -52,8 +58,9 @@ describe Cache do
|
|||
end
|
||||
|
||||
it "can fetch existing correctly" do
|
||||
key = cache.namespaced_key("key")
|
||||
|
||||
$redis.expects(:get).with("key").returns "bill"
|
||||
$redis.expects(:get).with(key).returns "bill"
|
||||
|
||||
r = cache.fetch "key" do
|
||||
"bob"
|
||||
|
|
Reference in a new issue