public async Task <PagedQueryResult> QueryAsync(string queryName, string query, int pageSize, int currentPage, bool skipCache = false)
        {
            if (skipCache == false && _memoryCache.TryGetValue(queryName, out PagedQueryResult cachedQueryResult))
            {
                return(cachedQueryResult);
            }

            var queryResult = await _azureResourceGraph.QueryTargetSubscriptionsAsync(queryName, query, pageSize, currentPage);

            AddCacheEntry(queryName, queryResult);

            return(queryResult);
        }
        /// <summary>
        ///     Get resources that are part of a given resource collection
        /// </summary>
        /// <param name="resourceDiscoveryGroupName">Name of the resource collection</param>
        /// <param name="pageSize">The amount of results that are allowed per page</param>
        /// <param name="currentPage">Current page that is being queried</param>
        public virtual async Task <PagedPayload <AzureResourceDefinition> > GetResourcesAsync(string resourceDiscoveryGroupName, int pageSize, int currentPage)
        {
            var resourceDeclaration = _resourceDeclarationMonitor.CurrentValue;
            var resourceDiscoveryGroupDefinition = resourceDeclaration.ResourceDiscoveryGroups.SingleOrDefault(collection => collection.Name.Equals(resourceDiscoveryGroupName, StringComparison.InvariantCultureIgnoreCase));

            if (resourceDiscoveryGroupDefinition == null)
            {
                // No collection found so nothing to return
                return(null);
            }

            var resourceDiscovery = ResourceDiscoveryFactory.UseResourceDiscoveryFor(resourceDiscoveryGroupDefinition.Type);

            // 1. Create query per type
            var query = resourceDiscovery.DefineQuery(resourceDiscoveryGroupDefinition.Criteria).Build();

            // 2. Run Query
            var unparsedResults = await _azureResourceGraph.QueryTargetSubscriptionsAsync(resourceDiscoveryGroupName, query, pageSize, currentPage);

            // 3. Parse query results into resource
            var foundResources = resourceDiscovery.ParseQueryResults(unparsedResults.Result);

            var contextualInformation = new Dictionary <string, object>
            {
                { "ResourceType", resourceDiscoveryGroupDefinition.Type },
                { "CollectionName", resourceDiscoveryGroupName }
            };

            // Log a metric with amount of discovered resources
            // But only if the current page is 1, or we'll emit it too much
            if (currentPage == 1)
            {
                _logger.LogMetric("Discovered Resources", unparsedResults.TotalRecords, contextualInformation);
            }

            return(new PagedPayload <AzureResourceDefinition>(foundResources, unparsedResults.TotalRecords, unparsedResults.CurrentPage, unparsedResults.PageSize));
        }