<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>6233843 (马斯费油)</title>
    <link>https://ruby-china.org/6233843</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>2015 ruby conf china 怎么投稿呀？</title>
      <description>&lt;p&gt;今年准备投一个话题试试&lt;/p&gt;</description>
      <author>6233843</author>
      <pubDate>Thu, 02 Jul 2015 10:06:50 +0800</pubDate>
      <link>https://ruby-china.org/topics/26280</link>
      <guid>https://ruby-china.org/topics/26280</guid>
    </item>
    <item>
      <title>请教，多参考项的随机分组？</title>
      <description>&lt;p&gt;问题大概是这样的：有这样一群人，分别来自 A，B，C 地区，毕业于 M，N，O 等大学，综合评价分别是优、良、差，性别当然是男和女 -_-
1.如何考虑学校，地区，综合评价，性别把他们更分散的分成几组？比如不要同一学校扎堆，同一地区扎堆等
2.是否存在一种算法，可以让我再加入/减少其他参考项，比如年龄分为老中青
3.这种问题是否由典型例题，比如斐波那契数列就来自兔子
向大家请教&lt;/p&gt;

&lt;p&gt;我也在知乎请教大家了
&lt;a href="http://www.zhihu.com/question/23999896" rel="nofollow" target="_blank"&gt;http://www.zhihu.com/question/23999896&lt;/a&gt;&lt;/p&gt;</description>
      <author>6233843</author>
      <pubDate>Tue, 03 Jun 2014 22:46:43 +0800</pubDate>
      <link>https://ruby-china.org/topics/19714</link>
      <guid>https://ruby-china.org/topics/19714</guid>
    </item>
    <item>
      <title>关于 cahce 的种种问题，请教大家</title>
      <description>&lt;p&gt;Hi，大家好
最近看到了两篇质量很高的 cache 文章，其中有不少精彩的评论，看完之后我却有一些自己实践中的问题，不搞清楚的话有点难受，请大家把我当新手对待。同时也期待大家多用使用测试结果说话，我也会做做实验贴上答案。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. 对于静态资源文件，需要 nginx 把资源文件变成文件 cache 么？&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="n"&gt;root&lt;/span&gt; /&lt;span class="n"&gt;var&lt;/span&gt;/&lt;span class="n"&gt;www&lt;/span&gt;/&lt;span class="n"&gt;current&lt;/span&gt;/&lt;span class="n"&gt;public&lt;/span&gt;;
&lt;span class="n"&gt;location&lt;/span&gt; ~* ^(/&lt;span class="n"&gt;assets&lt;/span&gt;|/&lt;span class="n"&gt;favicon&lt;/span&gt;.&lt;span class="n"&gt;ico&lt;/span&gt;|&lt;span class="n"&gt;images&lt;/span&gt;|&lt;span class="n"&gt;javascripts&lt;/span&gt;|&lt;span class="n"&gt;stylesheets&lt;/span&gt;|&lt;span class="n"&gt;img&lt;/span&gt;) {
  &lt;span class="n"&gt;log_not_found&lt;/span&gt;     &lt;span class="n"&gt;off&lt;/span&gt;;
  &lt;span class="n"&gt;access_log&lt;/span&gt;        &lt;span class="n"&gt;off&lt;/span&gt;;
  &lt;span class="n"&gt;expires&lt;/span&gt;           &lt;span class="n"&gt;max&lt;/span&gt;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;上述配置会直接让 nginx 读取资源文件返回，并且结合 assets pipeline 的后缀我们可以让它永不过期。可目前 nginx 自己是可以进行 cache 的，比如 memcached 或者 file system，那么我还需要将 nginx 读取文件系统切换成 nginx 读取文件 cache 么？我猜想切换成 ngxin 读取 memcached 肯定效果会好。&lt;a href="https://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/" rel="nofollow" target="_blank" title=""&gt;文章见此&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. 大家使用 last modified 还是 etag？&lt;/strong&gt;
我读了&lt;a href="https://devcenter.heroku.com/articles/http-caching-ruby-rails" rel="nofollow" target="_blank" title=""&gt;文章 1&lt;/a&gt;和&lt;a href="https://devcenter.heroku.com/articles/increasing-application-performance-with-http-cache-headers" rel="nofollow" target="_blank" title=""&gt;文章 2&lt;/a&gt;，没有发现推荐一定使用哪一个。所以我想问问大家倾向于哪一个方案，有什么优缺点？&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Rack::ETag 到底有用没用？&lt;/strong&gt;
根据&lt;a href="http://rack.rubyforge.org/doc/Rack/ETag.html" rel="nofollow" target="_blank" title=""&gt;Rack::ETag&lt;/a&gt;的定义，他会给没有 last-modified or etag 的 response 补上 etag，我觉得挺有用的呀，为什么有人说可以删除，在什么情况下会没有用呢？&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. conditional get 还是 action cache, fragment cache？&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def show
    @component = Component.find(params[:id])
    if stale? etag: @component
      render some_page
    end
  end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;上面的代码是 conditional_get，我的理解是系统不会再次 render，而直接返回 http code 是 304，内容是空的 response。需要付出的是为了得到 etag 或者 last_modified 的 key 而查询数据库，以及比较 etag 的计算。&lt;/p&gt;

&lt;p&gt;另一种方案&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;% cache @component do %&amp;gt;
...
&amp;lt;% end %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;如果使用 fragment cache 的 view，而使用 action cache 的配置更简单，直接&lt;code&gt;caches_action :index&lt;/code&gt;。如果是 fragment cache，我们需要付出的和 conditional get 一样，只是 rails 会返回 200 带内容的 response，而对 action cache 而言，需要当 cache 资源发生变化时，调用 expire_action 失效之前所 cache 的内容。
与 conditional get 相比，假设都需要从数据库查询一次来判定是否过期，返回 304 和返回 200 带内容失效差不多的情况下，200 带内容总会比 304 慢，因为 304 传输没有内容。我这样理解对么？我是否忽略了其他的因素对传输带来的影响？大家都是怎么使用 conditional get, fragment cache 呢？(我猜测 action cache 用的人不多)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.我们是否能把从浏览器发送 request 到收到 response 过程中和 cache 相关的动作整理出来？&lt;/strong&gt;
包括 nginx 端和 unicorn 端，具体粒度还没有想好，但最起码大体概念应该保证大家统一。这个东西我会持续更新，欢迎大家多提意见。&lt;/p&gt;</description>
      <author>6233843</author>
      <pubDate>Mon, 26 May 2014 17:02:50 +0800</pubDate>
      <link>https://ruby-china.org/topics/19545</link>
      <guid>https://ruby-china.org/topics/19545</guid>
    </item>
    <item>
      <title>多台机器上 Unicorn 共享 Session</title>
      <description>&lt;p&gt;Hi，各位
问一个找了几天都没有满意答案的问题，欢迎大家讨论。&lt;/p&gt;

&lt;p&gt;Rails 默认的 Session 是 CookieStore，也就是存在 Cookie 里面，随着每次发送的 request 到服务器端，供服务器解析。&lt;/p&gt;

&lt;p&gt;一旦我有多台机器，就会面临在 A 机器上登陆的用户可能下次请求被 redirect 到 B 机器而导致 Session 丢失。解决方案是使用数据库或者 Memcached 单独把 Session 存起来，这样多台机器都共同访问一个 Session 池，就不会发生上述问题了。&lt;/p&gt;

&lt;p&gt;但我想，既然 CookieStore 是在 Cookie 里的，每次 request 里面既有 Cookie 也有 CookieSession，是不是 CookieStore 自然就能多机器共享 Session，而不用再搭建 Memcached 或者 DB 的 Session 池？&lt;/p&gt;

&lt;p&gt;再请教大家都是怎么做的？有什么优缺点？
欢迎指教 :)&lt;/p&gt;</description>
      <author>6233843</author>
      <pubDate>Sun, 25 May 2014 12:06:27 +0800</pubDate>
      <link>https://ruby-china.org/topics/19520</link>
      <guid>https://ruby-china.org/topics/19520</guid>
    </item>
    <item>
      <title>rspec feature test 导致 rails 服务器卡死</title>
      <description>&lt;p&gt;Hi，最近遇到一个非常奇怪的问题
我用 capybara + rspec feature test，当运行测试时，发现测试服务器卡住了，现象就是等待载入页面资源，可能是一个 js，或者 png 等，之前怀疑是 js 的问题，但发现测试卡住之后，用其他浏览器访问时同样出现卡住得情况，而且服务器 log 没有任何更新，所以判断是服务器卡住了。更奇怪的事时好时坏，而且没有任何代码改动，不知道大家遇到过么？&lt;/p&gt;

&lt;p&gt;系统：mac 10.9.2
ruby: 2.1.0
rails: 4.0.2
rspec: 2.14.1
rspec-rails: 2.14.1
capybara: 2.2.0&lt;/p&gt;</description>
      <author>6233843</author>
      <pubDate>Wed, 07 May 2014 23:33:26 +0800</pubDate>
      <link>https://ruby-china.org/topics/19089</link>
      <guid>https://ruby-china.org/topics/19089</guid>
    </item>
    <item>
      <title>使用 Mongodb 的亲，部署时你怎么做 migration 呀？</title>
      <description>&lt;p&gt;原来使用 mysql+active record，capistrano 部署时轻轻松松搞定 migration。现在尝试 mongodb 了，不知道还是像原来一样生成 migration 文件，用 capistrano 部署时进行 migration 么？大家的 mongodb migration 都怎么做的？&lt;/p&gt;</description>
      <author>6233843</author>
      <pubDate>Sun, 20 Apr 2014 15:07:00 +0800</pubDate>
      <link>https://ruby-china.org/topics/18734</link>
      <guid>https://ruby-china.org/topics/18734</guid>
    </item>
    <item>
      <title>使用 Dash.app 老版本的千万不要升级</title>
      <description>&lt;p&gt;Dash 离线查看 API 的工具，1.6 之前的 Dash 很好用
最新版本如果你没有付费的话，每一个查询要等待 10 秒，简直要人命呀。。。&lt;/p&gt;

&lt;p&gt;如果你没有用 Dash，请忽略
如果你用 Dash，千万不要升级。。。&lt;/p&gt;

&lt;p&gt;顺便八卦一下
大家平时怎么看 API，用没有什么好用的工具？&lt;/p&gt;</description>
      <author>6233843</author>
      <pubDate>Sun, 18 Nov 2012 22:13:12 +0800</pubDate>
      <link>https://ruby-china.org/topics/6880</link>
      <guid>https://ruby-china.org/topics/6880</guid>
    </item>
    <item>
      <title>什么时候使用 module，什么时候使用 class</title>
      <description>&lt;p&gt;一段逻辑既可以做一个 module，也可以做一个 class
老早之前就在纠结这个问题，实在找不出个界限&lt;/p&gt;

&lt;p&gt;最近和同事讨论了一下，有了新的认识，和大家讨论一下
1.module 比较关注的是功能方面，它把方法收集在一起，组成一个特殊的上下文，通常表示一种能力，比如 Enumerable。
2.class 就是我们所理解的经典的类，它可以创建实例对象，包含实例变量和类变量，一般通过对象来与外界交流。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;除了这些，我认为 class 通常都是逻辑完整的，甚至能在现实世界中找到对应物，而对 module 来说却很难是逻辑完整的，因为 module 只能描述一个特殊的上下文，而这个上下文通常无法组成一个完整的对象，需要被找一个宿主，而这个宿主有可能是 class，也有可能是 module&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;不知道大家有什么看法？欢迎讨论&lt;/p&gt;</description>
      <author>6233843</author>
      <pubDate>Wed, 22 Aug 2012 23:55:02 +0800</pubDate>
      <link>https://ruby-china.org/topics/5096</link>
      <guid>https://ruby-china.org/topics/5096</guid>
    </item>
  </channel>
</rss>
