Solution based on mean-vector-cache example.