Skip to content

Instantly share code, notes, and snippets.

@jkriss
Last active December 21, 2015 06:29
Show Gist options
  • Save jkriss/6264758 to your computer and use it in GitHub Desktop.
Save jkriss/6264758 to your computer and use it in GitHub Desktop.
def Crop.interesting
puts "WHAT'S IN THE CACHE NOW?"
puts Rails.cache.read("interesting_crops").to_yaml
json_crops = Rails.cache.fetch("interesting_crops", :expires_in => 1.day) do
howmany = 12 # max number to find
interesting_crops = Array.new
Crop.randomized.each do |c|
break if interesting_crops.length == howmany
next unless c.interesting?
interesting_crops.push(c)
end
puts "CROPS TO CACHE:"
puts interesting_crops.to_yaml
interesting_crops.to_json
end
return json_crops.collect{ |json_crop| Crop.new(json_crop) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment