Adds a cache to compute neighborhood only once.