コード例 #1
0
        /// <summary>
        /// 以 Id 取得資料
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns>Foo.</returns>
        public async Task <FooModel> GetAsync(Guid id)
        {
            var stepName = $"{nameof(CachedFooRepository)}.{nameof(this.GetAsync)}";

            using (ProfilingSession.Current.Step(stepName))
            {
                var cacheItem = await this.GetOrAddCacheItemAsync
                                (
                    cachekey : Cachekeys.Foo.Get.ToFormat(id),
                    cacheItemExpiration : CacheUtility.GetCacheItemExpiration5Min(),
                    source : async() =>
                {
                    var result = await this.FooRepository.GetAsync(id);
                    return(result);
                }
                                );

                return(cacheItem);
            }
        }
コード例 #2
0
        /// <summary>
        /// 以 FooId 確認資料是否存在
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public async Task <bool> IsExistsAsync(Guid id)
        {
            var stepName = $"{nameof(CachedFooRepository)}.{nameof(this.IsExistsAsync)}";

            using (ProfilingSession.Current.Step(stepName))
            {
                var cacheItem = await this.GetOrAddCacheItemAsync
                                (
                    Cachekeys.Foo.Exists.ToFormat(id),
                    CacheUtility.GetCacheItemExpiration5Min(),
                    async() =>
                {
                    var result = await this.FooRepository.IsExistsAsync(id);
                    return(result);
                }
                                );

                return(cacheItem);
            }
        }