Notes posted by kratob
RSS feed
Confusing log output
If you do a single Rails.cache.read('my_key'), your will usually see in your log something like
Cache read: my_key Cache read: my_key Cache write: my_key
Don’t worry about this.
What happens here is this: Before going to memcached, rails will first ask a local MemoryStore cache (which is responsible for the first and third line in the log), before falling through to memcached. This local cache is destroyed after each request.
Source is in activesupport/lib/active_support/cache/strategy/local_cache.rb.

Careful with scopes
Just like find, find_in_batches introduces an implicit scope into the block. So for example
Person.find_in_batches(:conditions => {:birthday => Date.today}) do |birthday_childs| Person.all.each do |person| person.send_presents_to(birthday_childs) end end
does not work as expected, because the Person.all within the block will also find only persons with :conditions => {:birthday => Date.today}.