Exemplo n.º 1
0
        private static string GenerateKey(SearchProperties rawKey)
        {
            const string separator = "?";

            var generatedKey = new StringBuilder();

            generatedKey.Append(separator);

            for (int currentPropertyIndex = 0; currentPropertyIndex < rawKey.List.Count - 1; currentPropertyIndex++)
            {
                generatedKey.Append($"{rawKey.List[currentPropertyIndex]}={rawKey.List[currentPropertyIndex + 1]}{separator}{rawKey.Signs[currentPropertyIndex]}{separator}");
            }

            return(generatedKey.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Selects records by the specified key-value pairs.
        /// </summary>
        /// <param name="searchProperties">Search properties.</param>
        /// <returns>Enumerable collection of records.</returns>
        public IEnumerable <FileCabinetRecord> Select(SearchProperties searchProperties)
        {
            if (searchProperties is null)
            {
                throw new ArgumentNullException(nameof(searchProperties));
            }

            var key = GenerateKey(searchProperties);

            if (!this.RequestCache.TryGetValue(key, out IEnumerable <FileCabinetRecord> records))
            {
                records = service.SelectByCriteria(searchProperties);
                this.RequestCache.Add(key, records);
            }

            return(records);
        }