0

I am learning about memcached with rails application.

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

This code checks weather 'key' available in cache. If the 'key' is available, then it won't execute the block code. Otherwise execute the block and store the result in 'key'. This is pretty easy and more readable. My doubt is how to do the same thing in Dalli::Client? For example,

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

I do not like to check dc.get('key').nil?. If nil store the new value. If i misunderstood anything, please let me know. Or how can i improve Dalli::Client knowledge.

0 Answers0