mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
DEV: Implement a faster Discourse.cache
This is a bottom up rewrite of Discourse cache to support faster performance and a limited surface area. ActiveSupport::Cache::Store accepts many options we do not use, this partial implementation only picks the bits out that we do use and want to support. Additionally params are named which avoids typos such as "expires_at" vs "expires_in" This also moves a few spots in Discourse to use Discourse.cache over setex Performance of setex and Discourse.cache.write is similar.
This commit is contained in:
@ -9,6 +9,12 @@ describe Cache do
|
||||
Cache.new
|
||||
end
|
||||
|
||||
it "supports exist?" do
|
||||
cache.write("testing", 1.1)
|
||||
expect(cache.exist?("testing")).to eq(true)
|
||||
expect(cache.exist?(SecureRandom.hex)).to eq(false)
|
||||
end
|
||||
|
||||
it "supports float" do
|
||||
cache.write("float", 1.1)
|
||||
expect(cache.read("float")).to eq(1.1)
|
||||
@ -36,10 +42,14 @@ describe Cache do
|
||||
end
|
||||
|
||||
it "can delete correctly" do
|
||||
cache.delete("key")
|
||||
|
||||
cache.fetch("key", expires_in: 1.minute) do
|
||||
"test"
|
||||
end
|
||||
|
||||
expect(cache.fetch("key")).to eq("test")
|
||||
|
||||
cache.delete("key")
|
||||
expect(cache.fetch("key")).to eq(nil)
|
||||
end
|
||||
@ -69,6 +79,7 @@ describe Cache do
|
||||
r = cache.fetch "key" do
|
||||
"bob"
|
||||
end
|
||||
|
||||
expect(r).to eq("bob")
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user