From 6d8e0318be2f63b7ab600b9f35517dc3be6deaf3 Mon Sep 17 00:00:00 2001 From: Jonathan Hyman Date: Mon, 8 Jul 2013 17:40:25 -0400 Subject: [PATCH] Explain that cache is not a real cache. --- source/en/mongoid/docs/extras.haml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source/en/mongoid/docs/extras.haml b/source/en/mongoid/docs/extras.haml index 4b61090..e265639 100644 --- a/source/en/mongoid/docs/extras.haml +++ b/source/en/mongoid/docs/extras.haml @@ -31,6 +31,19 @@ #!ruby Person.where(first_name: "Franziska").cache + %p + The Mongoid cache is not a true cache - it simply keeps documents in + memory if you iterate over the same Criteria. That is, this will hit + the database twice: + + :coderay + #!ruby + query = Person.where(first_name: "Jon").cache + query.each { |p| puts(p) } + query2 = Person.where(first_name: "Jon").cache + # This will make another database call because query2 is a new Criteria + query2.each { |p| puts(p) } + %section#paranoia %h2 Paranoid Documents