在研究了DHH和其他关于基于密钥的缓存过期和俄罗斯娃娃缓存的博客文章之后,我仍然不确定如何处理一种关系类型.具体来说,是一种has_many
关系.
我将分享我对示例应用程序的研究结果.这是一个故事讲述,所以坚持下去.假设我们有以下ActiveRecord模型.我们所关心的只是模型的正确改变cache_key
,对吗?
class Article < ActiveRecord::Base
attr_accessible :author_id, :body, :title
has_many :comments
belongs_to :author
end
class Comment < ActiveRecord::Base
attr_accessible :article_id, :author_id, :body
belongs_to :author
belongs_to :article, touch: true
end
class Author < ActiveRecord::Base
attr_accessible :name
has_many :articles
has_many :comments
end
Run Code Online (Sandbox Code Playgroud)
我们已经有一篇文章,只有一条评论.两者都是由不同的作者.目标是cache_key
在以下情况下对文章进行更改:
因此,默认情况下,我们对案例1和案例2都有好处.
1.9.3-p194 :034 > article.cache_key
=> "articles/1-20130412185804"
1.9.3-p194 :035 > article.comments.first.update_attribute('body', 'First Post!')
1.9.3-p194 :038 > article.cache_key
=> "articles/1-20130412185913"
Run Code Online (Sandbox Code Playgroud)
但不是案例3.
1.9.3-p194 :040 > article.author.update_attribute('name', 'Adam A.')
1.9.3-p194 :041 …
Run Code Online (Sandbox Code Playgroud) ruby caching ruby-on-rails fragment-caching russian-doll-caching
默认情况下,Selenium在我使用Cucumber定义的场景中尽可能快地运行.我想将它设置为以较低的速度运行,因此我能够捕获该过程的视频.
我想出了一个Selenium::Client::Driver
有一个set_speed
方法的实例.这与Java API相对应.
我怎样才能获得Selenium::Client::Driver
该类的实例?我可以得到page.driver
,但它返回一个实例Capybara::Driver::Selenium
.
使用Elasticsearch的突出显示功能:
"highlight": {
"fields": {
"tags": { "number_of_fragments": 0 }
}
}
Run Code Online (Sandbox Code Playgroud)
使用时number_of_fragments: 0
,不会生成任何片段,但会返回该字段的全部内容.这对于短文本很有用,因为文档可以正常显示,人们可以轻松扫描突出显示的部分.
当文档包含具有多个值的数组时,如何使用它?
PUT /test/doc/1
{
"tags": [
"one hit tag",
"two foo tag",
"three hit tag",
"four foo tag"
]
}
GET /test/doc/_search
{
"query": {
"match": { "tags": "hit"}
},
"highlight": {
"fields": {
"tags": { "number_of_fragments": 0 }
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想向用户展示:
1结果:
文件1,标记为:
"one hit tag","two foo tag","three hit tag","four foo tag"
不幸的是,这是查询的结果:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5, …
Run Code Online (Sandbox Code Playgroud) 在 stackoverflow 上的另一篇文章中,我读到它INSTR
可用于按相关性对结果进行排序。
我对 INSTR(col, \'str\')` 的理解col LIKE \'%str%\' and
是它们的行为相同。处理排序规则的方式似乎有所不同。
CREATE TABLE `users` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `name` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\nINSERT INTO users (name)\nVALUES (\'Jo\xc3\xabl\'), (\'Ren\xc3\xa9\');\n\nSELECT * FROM users WHERE name LIKE \'%joel%\'; -- 1 record returned\nSELECT * FROM users WHERE name LIKE \'%rene%\'; -- 1 record returned\nSELECT * FROM users WHERE INSTR(name, \'joel\') > 0; -- 0 records returned\nSELECT * FROM users …
Run Code Online (Sandbox Code Playgroud)