Added a firstObject/lastObject cache checks.

Basically the contents of https://gist.github.com/mmun/877bad33158578a8609b