More details in the counter cache documentation