Ejemplo n.º 1
0
        public static async Task <IEnumerable <BaseEntity> > GetOrSetCacheEntry
            (IPropertyViewModelService propertyViewModelService,
            IMemoryCache cache,
            CacheKey key)
        {
            IEnumerable <BaseEntity> result;

            if (!cache.TryGetValue(key, out result))
            {
                switch (key)
                {
                case CacheKey.Property:
                    result = await propertyViewModelService.GetPropertyTypes();

                    break;

                case CacheKey.Location:
                    result = await propertyViewModelService.GetEstateLocations();

                    break;
                }

                var options = new MemoryCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddMinutes(30));
                cache.Set(key, result, options);
            }

            return(result);
        }