Caching rules

Pull request so I can test if I haven't broken anything.
Not ready for code review.