added conditional cache on getDistinctValuesCount