public Person Get(int id)
        {
            string personId = $"person{id}";

            if (_cacheAdapter.Exists(personId))
            {
                return(_cacheAdapter.Get <Person>(personId));
            }
            Person person = _personRepository.Get(id);

            _cacheAdapter.Add(personId, person);
            return(person);
        }
Exemplo n.º 2
0
        public async Task <TEntity> FirstItemAsync(Expression <Func <TEntity, bool> > predicate, CancellationToken cancellationToken)
        {
            string key = string.Concat(SingleObjectCacheKey, predicate.Body.ToString());

            if (CacheAdapter.Exist(key))
            {
                return(CacheAdapter.Get <TEntity>(key));
            }
            else
            {
                TEntity entity = await _repository.FirstItemAsync(predicate, cancellationToken);

                CacheAdapter.Add(key, entity);
                return(entity);
            }
        }
Exemplo n.º 3
0
        public async Task <List <TagModel> > GetTags()
        {
            const string cacheKey   = "TagList";
            var          cachedTags = await _cacheAdapter.Get <List <TagModel> >(cacheKey);

            if (cachedTags != null)
            {
                return(cachedTags);
            }

            var tags = _louisvilleDemographicsContext.Tags
                       .Select(t => new TagModel {
                PostalAbbreviation = t.USPSStandardAbbreviation,
                Name = t.Name
            }).ToList();

            await _cacheAdapter.Add(cacheKey, tags, TimeSpan.FromMinutes(_cacheSettings.CacheTagsMinutes));

            return(tags);
        }
Exemplo n.º 4
0
        public async Task <List <string> > GetZipCodes()
        {
            const string cacheKey       = "ZipCodeList";
            var          cachedZipCodes = await _cacheAdapter.Get <List <string> >(cacheKey);

            if (cachedZipCodes != null)
            {
                return(cachedZipCodes);
            }

            var zipCodes = _louisvilleDemographicsContext.Addresses
                           .Where(a => a.Zip != null)
                           .Select(a => a.Zip)
                           .Distinct().ToList();

            await _cacheAdapter.Add(cacheKey, zipCodes, TimeSpan.FromMinutes(_cacheSettings.CacheTagsMinutes));

            return(zipCodes);
        }