add caching to distinct