2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2017-06-10 04:07:40 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "active_support/cache"
|
|
|
|
|
|
|
|
class CacheStoreNamespaceTest < ActiveSupport::TestCase
|
|
|
|
def test_static_namespace
|
|
|
|
cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: "tester")
|
|
|
|
cache.write("foo", "bar")
|
|
|
|
assert_equal "bar", cache.read("foo")
|
|
|
|
assert_equal "bar", cache.instance_variable_get(:@data)["tester:foo"].value
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_proc_namespace
|
|
|
|
test_val = "tester"
|
|
|
|
proc = lambda { test_val }
|
|
|
|
cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: proc)
|
|
|
|
cache.write("foo", "bar")
|
|
|
|
assert_equal "bar", cache.read("foo")
|
|
|
|
assert_equal "bar", cache.instance_variable_get(:@data)["tester:foo"].value
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delete_matched_key_start
|
|
|
|
cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: "tester")
|
|
|
|
cache.write("foo", "bar")
|
|
|
|
cache.write("fu", "baz")
|
|
|
|
cache.delete_matched(/^fo/)
|
2018-04-17 18:21:34 -04:00
|
|
|
assert_not cache.exist?("foo")
|
2017-06-10 04:07:40 -04:00
|
|
|
assert cache.exist?("fu")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delete_matched_key
|
|
|
|
cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: "foo")
|
|
|
|
cache.write("foo", "bar")
|
|
|
|
cache.write("fu", "baz")
|
|
|
|
cache.delete_matched(/OO/i)
|
2018-04-17 18:21:34 -04:00
|
|
|
assert_not cache.exist?("foo")
|
2017-06-10 04:07:40 -04:00
|
|
|
assert cache.exist?("fu")
|
|
|
|
end
|
|
|
|
end
|