FIX: ensures defined expired_in is passed from write to write_entry (#11622)

This commit also makes `Cache#namespace` readable to help writing tests easier and make them more robust.
This commit is contained in:
Joffrey JAFFEUX 2021-01-04 10:34:44 +01:00 committed by GitHub
parent 1405b6859d
commit 258888b7c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -22,6 +22,8 @@ class Cache
# pointless data # pointless data
MAX_CACHE_AGE = 1.day unless defined? MAX_CACHE_AGE MAX_CACHE_AGE = 1.day unless defined? MAX_CACHE_AGE
attr_reader :namespace
# we don't need this feature, 1 day expiry is enough # we don't need this feature, 1 day expiry is enough
# it makes lookups a tad cheaper # it makes lookups a tad cheaper
def self.supports_cache_versioning? def self.supports_cache_versioning?
@ -66,7 +68,7 @@ class Cache
end end
def write(name, value, expires_in: nil) def write(name, value, expires_in: nil)
write_entry(normalize_key(name), value, expires_in: nil) write_entry(normalize_key(name), value, expires_in: expires_in)
end end
def delete(name) def delete(name)

View File

@ -98,4 +98,14 @@ describe Cache do
expect(cache.keys("users:*").count).to eq(2) expect(cache.keys("users:*").count).to eq(2)
end end
it "can fetch namespace" do
expect(cache.namespace).to eq("_CACHE")
end
it "uses the defined expires_in" do
cache.write "foo:bar", "baz", expires_in: 3.minutes
expect(cache.redis.ttl("#{cache.namespace}:foo:bar")).to eq(180)
end
end end