stefankroes/ancestry — pull request #195 by brocktimus (2014-07-25 11:49:48+00:00)
Title: Implemented very simple caching to avoid unnecessary database queries

I had some code which was calling ```#parent``` a lot. Rails ```:belongs_to``` caches this to avoid hitting the database unnecessarily. After migrating to ancestry I noticed it was much slower because every call to ```#parent``` resulted in the database being hit.

This is obviously an incredibly naive / trivial cache and doesn't bother to even try to cache the more complex methods.

We could make it an opt in argument passed to ```::has_ancestry```, but that seems really conservative.

Any idea how to test this? Can we assert on number of queries run? Otherwise I'll write a test now asserting on the object equality, potentially through ```#object_id```.