如何在使用rails的memcached中检查密钥是否可用

时间:2014-06-04 07:58:07

标签: ruby-on-rails memcached dalli

我正在学习使用rails应用程序的memcached。

Rails.cache.fetch('key') do
  "This is the string to store in key"
end

此代码检查天气'键'在缓存中可用。如果'键'可用,然后它不会执行块代码。否则执行该块并将结果存储在'键'中。这非常简单,更易读。我怀疑在Dalli :: Client中如何做同样的事情?例如,

dc = Dalli::Client.new('localhost:11211')
dc.fetch('key') do 
   "This is the string to store in key"
end

我不想查看dc.get(' key')。nil?。如果nil存储新值。 如果我误解了什么,请告诉我。或者我如何改善Dalli ::客户知识。

0 个答案:

没有答案
相关问题