require 'rails_helper'
require 'distributed_cache'
describe DistributedCache do
let! :cache1 do
DistributedCache.new("test")
end
let! :cache2 do
it 'allows us to store Set' do
c1 = DistributedCache.new("test1")
c2 = DistributedCache.new("test1")
set = {a: 1, b: 1}
set = Set.new
set << 1
set << "b"
c1["cats"] = set
wait_for do
c2["cats"] == set
expect(c2["cats"]).to eq(set)
set << 5
c1["cats"] == set
expect(c1["cats"]).to eq(set)
it 'does not leak state across caches' do
c3 = DistributedCache.new("test1")
c2["hi"] = "hi"
c3["hi"] == "hi"
Thread.pass
expect(cache1["hi"]).to eq(nil)
it 'allows coerces symbol keys to strings' do
cache1[:key] = "test"
expect(cache1["key"]).to eq("test")
cache2[:key] == "test"
expect(cache2["key"]).to eq("test")
it 'sets other caches' do
cache1["test"] = "world"
cache2["test"] == "world"
it 'deletes from other caches' do
cache1["foo"] = "bar"
cache2["foo"] == "bar"
cache1.delete("foo")
expect(cache1["foo"]).to eq(nil)
cache2["foo"] == nil
it 'clears cache on request' do
cache1.clear
cache2["boom"] == nil