Tag: dalli

如何使用dalli和Rails增加1MB以上的memcache slab大小?

我正在使用Ruby on Rails和dalli gem来使用memcache进行缓存。 默认值(键值存储中的值,即slab)最大大小为1MB。 我想把它增加到2MB。 dalli的文档说: value_max_bytes: The maximum size of a value in memcached. Defaults to 1MB, this can be increased with memcached’s -I parameter. You must also configure Dalli to allow the larger size here. 使用memcached的-I选项,如何指定2MB? 是-I2还是-I2000? (文件不清楚) 对于dalli gem,我有environments/development.rb .rb config.cache_store = :dalli_store 我没有明确提到Dalli :: Client.new那么如何设置value_max_bytes ? 我已经查看了stackoverflow上的相关问题 ,似乎我需要安装rack-cache gem。 这有必要吗? […]

如何使用Dalli更新MemCached中的到期时间?

我正在使用Ruby on Rails(v3.2.13),Dalli(v2.6.4)和MemCached(v1.4.13)。 我像这样缓存: result = Rails.cache.fetch(“test_key”, :expires_in => 1.week) do get_data() # slow call, result of which should be cached end 我想根据数据更新缓存过期日期,因为我的一些数据可以保存更长时间。 现在,以下代码完成了这项工作: if keep_longer(result) Rails.cache.write(“test_key”, result, :expires_in => 6.months) end 我知道MemCached支持“touch”命令,允许更新到期日期而不发送值。 我不知道如何通过Dalligem使用它。 有没有办法更新到期日期而不重新发送结果? 更新: Rails.cache.dalli.touch(‘some_key’, 24.hours) 这应该有效,但对我来说却没有。 对你起作用吗? 这是您可以尝试的小例子。 在IRB中执行以下代码之后 dc = Dalli::Client.new(“localhost:11211”) dc.set(“test_key”, “test_value”, 5.minutes) dc.set( “key”, “value”, 5.minutes) dc.touch( “key”, 10.minutes) […]

通过正则表达式使memcache过期

我在我的rails应用程序中使用memcache。 我想说 使用“foo-123- *”等键过期所有条目 其中*是任何字符串。 当然,没有memcache发行版直接支持这个(对吧?),因为它的构建简单快速,因此它没有索引。 通过保留本地密钥列表,有几个项目可以解决这个问题: https://github.com/defconomicron/dalli-store-extensions https://github.com/jkassemi/memcache-store-extensions 但是将列表保留在内存中…该列表可能会在应用程序实例之间变得不同步……所以它不可靠。 这个问题是以另一种方式解决的吗? 我错过了常见的解决方案吗?

Rails Cache Key生成为ActiveRecord :: Relation

我正在尝试生成一个片段缓存(使用Dalli / Memcached存储)但是密钥是使用“#”生成的,因为Rails似乎没有认识到存在缓存值并且正在命中数据库。 我在视图中的缓存键如下所示: cache([@jobs, “index”]) do 控制器有: @jobs = @current_tenant.active_jobs 使用这样的实际Active Record查询: def active_jobs self.jobs.where(“published = ? and expiration_date >= ?”, true, Date.today).order(“(featured and created_at > now() – interval ‘” + self.pinned_time_limit.to_s + ” days’) desc nulls last, created_at desc”) end 查看rails服务器,我看到缓存读取,但SQL查询仍然运行: Cache read: views/#/1-index Read fragment views/#/1-index (1.0ms) (0.6ms) SELECT COUNT(*) FROM “jobs” […]

Rails + Dalli memcache gem:DalliError:没有可用的服务器

嗨,我在服务器上设置我的Rails项目时遇到了麻烦,因为apache一直在抱怨 DalliError: No server available 。 我在我的ubuntu机器上安装了memcached ,但它仍然无效。 我的rails项目在环境/ production.rb中也有config.cache_store = :dalli_store, ‘localhost:11211’, { :namespace => “production” } 。 我该如何调试? 我的日志显示在每个请求之前: localhost:11211 failed (count: 6) DalliError: No server available telnet到11211: root@s2:/usr/local/www/production/current/log# telnet localhost 11211 Trying 127.0.1.1… telnet: Unable to connect to remote host: Connection refused