Created
December 4, 2011 18:24
-
-
Save hammerdr/1430907 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class User | |
include Mongoid::Document | |
field :name | |
end | |
users = User.all.cache | |
users.each { |u| puts u } # Database hit | |
users.each { |u| puts u } # No database hit | |
class Post | |
include Mongoid::Document | |
cache | |
field :name | |
embeds_many :comments | |
end | |
posts = Post.all | |
posts.each { |p| puts p } # Database hit | |
posts.each { |p| puts p } # No database hit (even for the comments) | |
class Doctor | |
include Mongoid::Document | |
cache | |
references_many :patients | |
end | |
doctors = Doctor.all | |
doctors.each { |d| puts d } # Database hit | |
doctors.each { |d| puts d } # Not really sure? Is this a database hit for the references? | |
def users | |
User.all.cache | |
end | |
def index | |
if users.count > 5 # Database hit | |
render_for(users) # Database hit because we're defining a new | |
criteria | |
else | |
... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment