Imagine I有5个标签:tag1,tag2...tag5
。 如果是:
Rails.cache.fetch("all.tags") { Tag.all }
之后 页: 1 如果我增加另一个标签,而且我试图再次从海滩上挑出来,新标签也装上了。 为什么如此?
EDIT:我的实际法典如下:
Rails.cache.fetch("autocomplete.#{term}") { puts "Cache miss #{term}"; Tag.starting_with(term) }
当<条码>起步时,请从某些信件中找到标记。 这里,我的行为是:
1.9.3p125 :046 > Rails.cache.read("autocomplete.ta")
Tag Load (1.0ms) SELECT "tags".* FROM "tags" WHERE (name like ta% )
=> [#<Tag id: 10, name: "tag1">, #<Tag id: 11, name: "tag2">, #<Tag id: 12, name: "tag3">, #<Tag id: 13, name: "tag4">]
1.9.3p125 :048 > Tag.create(name:"tag5")
(0.2ms) begin transaction
SQL (1.0ms) INSERT INTO "tags" ("name") VALUES (?) [["name", "tag5"]]
(150.9ms) commit transaction
=> #<Tag id: 14, name: "tag5">
1.9.3p125 :049 > Rails.cache.read("autocomplete.ta")
Tag Load (0.8ms) SELECT "tags".* FROM "tags" WHERE (name like ta% )
=> [#<Tag id: 10, name: "tag1">, #<Tag id: 11, name: "tag2">, #<Tag id: 12, name: "tag3">, #<Tag id: 13, name: "tag4">, #<Tag id: 14, name: "tag5">]