move caching logic to query_dam