Last active
December 21, 2015 06:29
-
-
Save jkriss/6264758 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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