ruby-on-rails - Memcached 大小限制对于文件系统实体存储究竟代表什么?

标签 ruby-on-rails heroku memcached

下午好,

我在 Heroku 上的应用程序中连接了 Memcached。免费托管计划的限制为 Memcached 为 5MB,Memcachier 为 25MB。作为几乎所有事物的新手,我只是希望澄清这到底代表什么。

我在配置文件中设置了 DalliStore,并为 Rack::Cache 设置了典型选项。我的元存储在 Memcache 中,实体存储设置在文件系统上。

问题:

  • 这是否意味着我的 5/25MB 限制仅被我存储的关于每个缓存片段的元信息使用?这是否意味着我可以仅在免费计划中存储大量信息?
  • Rack::Cache 和 Memcache(通过 Dalli 商店?)之间的故障/故事究竟是什么?它们有不同的用途吗?他们在做同样的事情吗?即以下代码是多余的
    config.cache_store = :dalli_store


  • config.action_dispatch.rack_cache = {
      :verbose      => true,
      :metastore    => Dalli::Client.new,
      :entitystore  => 'file:tmp/cache/rack/body',
      :allow_reload => false
    }
    

    最佳答案

    我一直在努力解决类似的问题。

    首先,让我们弄清楚我们的术语。

  • 内存缓存 :在某个服务器上运行的进程(d 代表守护进程),它实际上将键值对存储在内存中。
  • cache_store :Rails 缓存存储 ( Rails.cache ) 具有单个 API,可以配置为使用不同的 Ruby 软件实现。 config.cache_store 的一种设置是 :memory_store使用内存中的实现。另一个设置是 :dalli_store指定使用 dalli gem,它在引擎盖下与您的 memcached 服务器建立可能的远程连接。
  • 达利店 :我假设你的意思是由 dalli gem 支持的 Rails 缓存,它在 memcached 中物理存储值。
  • 机架::缓存 :机架中间件,将 header (Expires、Cache-Control、ETag 等)插入到您的 HTTP 响应中,并且还充当反向代理缓存,尽可能在请求到达 Rails 堆栈之前处理请求。见 website .

  • 为了让 Rack::Cache 在请求到达 Rails 堆栈和应用程序的其余部分之前处理请求,它必须在某处存储响应 + 元数据。它存储东西的地方由 config.action_dispatch.rack_cache = { ... } 配置。环境。

    请注意,这是与 config.cache_store = :dalli_store 不同的设置.他们不必有关系。我认为这是很多困惑的来源。但在实践中,我们可能希望它们都使用 memcached,这意味着使用 dalli 实现。然而,他们每个人都有自己的Dalli::Client实例。 (此外,您的 session_store 可能是相关的,但不一定是。)

    Heroku cedar 堆栈有一个 ephemeral file system这不能在 dynos 之间共享。然而,Heroku 自己 recommend using tmp file storage with Rack::Cacheentitystore仅,memcached 用于 metastore .

    至于实际存储在 Rack::Cache 元存储中的内容,这些是来自 rack-cache v1.2 Rack::Cache::MetaStore 的文档。类(class):
    The MetaStore is responsible for storing meta information about a
    request/response pair keyed by the request's URL.
    
    The meta store keeps a list of request/response pairs for each canonical
    request URL. A request/response pair is a two element Array of the form:
      [request, response]
    
    The +request+ element is a Hash of Rack environment keys. Only protocol
    keys (i.e., those that start with "HTTP_") are stored. The +response+
    element is a Hash of cached HTTP response headers for the paired request.
    

    因此,为了回答您的问题,HTTP 请求 header 和 HTTP 响应 header 存储在 Rack::Cache 元存储中。另一方面,Rack::Cache 实体存储存储整个响应主体(即 HTML)。

    you can't use page caching reliably on Heroku ,这意味着您可能正在使用 Action 缓存和片段缓存。 Action 和片段缓存使用您的 Rails 缓存存储(而不是机架缓存)。但是,如果您将它们设置为在物理上使用相同的 memcached 服务器,则它们都将有助于内存使用。操作和部分缓存存储实际的 HTML。

    为了更深入地了解您的实际使用情况,如果您使用的是 memcachier,请运行以下命令在浏览器中打开分析仪表板。
    heroku addons:open memcachier
    

    this question有关获取 memcached 统计信息的更多信息。

    关于ruby-on-rails - Memcached 大小限制对于文件系统实体存储究竟代表什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10115187/

    相关文章:

    ruby-on-rails - rails : How to pass value from textfield to a partial

    ruby-on-rails - rspec 升级到 3.1.0 后,与 allowed_any_instance_of 一起使用的 and_call_original 不起作用

    ruby-on-rails - Heroku Websocket 到自定义域

    heroku - 如何解决 Heroku 部署上的 "Host key verification"错误?

    java - 是否有用于缓存文件的 Java 库?

    java - android应用程序,客户端的sqlite或服务器端的memcached哪个更好,请说明原因

    ruby-on-rails - 有没有一种方法可以测试(单元/集成)CSS 是否应用于预期的 HTML 元素?

    ruby-on-rails - 有没有人有使用 Ruby in Steel 的经验?

    ruby-on-rails - 当它为 "hung up"或没有响应时,如何推送到 Heroku 或获取信息/状态?

    php - 安装 php-pecl-memcached