public async Task <T> ExecuteAsync <T>(Func <Task <T> > action, CachePolicyType cachePolicyType, string policyName, string cacheContext)
        {
            switch (cachePolicyType)
            {
            case CachePolicyType.AbsoluteContext:
            case CachePolicyType.SlidingContext:
                if (!policyRegistry.ContainsKey(policyName))
                {
                    policyRegistry.Add(policyName, GetContextualAsyncPolicy());
                }

                var cachePolicy = policyRegistry.Get <IAsyncPolicy>(policyName);
                var contextData = new Dictionary <string, object>
                {
                    { ContextualTtl.TimeSpanKey, new Ttl(TimeSpan.FromMinutes(15)) },
                    { ContextualTtl.SlidingExpirationKey, cachePolicyType == CachePolicyType.SlidingContext }
                };

                return(await cachePolicy.ExecuteAsync(pollyContext => action(), new Context(cacheContext, contextData)));

            default:
                return(await Policy.NoOpAsync <T>().ExecuteAsync(action));
            }
        }
        public T Execute <T>(Func <T> action, CachePolicyType cachePolicyType, string policyName, string cacheContext)
        {
            switch (cachePolicyType)
            {
            case CachePolicyType.AbsoluteContext:
            case CachePolicyType.SlidingContext:
                if (!policyRegistry.ContainsKey(policyName))
                {
                    policyRegistry.Add(policyName, GetContextualPolicy());
                }

                var cachePolicy = policyRegistry.Get <ISyncPolicy>(policyName);
                var contextData = new Dictionary <string, object>
                {
                    [ContextualTtl.TimeSpanKey]          = TimeSpan.FromMinutes(15),
                    [ContextualTtl.SlidingExpirationKey] = cachePolicyType == CachePolicyType.SlidingContext
                };

                return(cachePolicy.Execute(pollyContext => action(), new Context(cacheContext, contextData)));

            default:
                return(Policy.NoOp <T>().Execute(action));
            }
        }