Lock and cache methods in Ruby.