Exemplo n.º 1
0
        public void SetCachePolicyManager()
        {
            var cpc = new CachePolicyConfig
            {
                Policies = new CachePolicyConfig.CachePolicyConfigPolicy[]
                {
                    new CachePolicyConfig.CachePolicyConfigPolicy
                    {
                        Name       = "MyTest",
                        Policy     = "Beef.Caching.Policy.SlidingCachePolicy, Beef.Core",
                        Properties = new CachePolicyConfig.CachePolicyConfigPolicyProperty[]
                        {
                            new CachePolicyConfig.CachePolicyConfigPolicyProperty {
                                Name = "Duration", Value = "00:30:00"
                            },
                            new CachePolicyConfig.CachePolicyConfigPolicyProperty {
                                Name = "MaxDuration", Value = "02:00:00"
                            },
                            new CachePolicyConfig.CachePolicyConfigPolicyProperty {
                                Name = "RandomizerOffset", Value = "00:10:00"
                            }
                        },
                        Caches = new string[] { "BlahX" }
                    }
                }
            };

            CachePolicyManager.SetFromCachePolicyConfig(cpc);

            var pol = CachePolicyManager.Get("BlahX");

            Assert.NotNull(pol);
            Assert.IsInstanceOf <SlidingCachePolicy>(pol);

            var scp = (SlidingCachePolicy)pol;

            Assert.AreEqual(new TimeSpan(00, 30, 00), scp.Duration);
            Assert.AreEqual(new TimeSpan(02, 00, 00), scp.MaxDuration);
            Assert.AreEqual(new TimeSpan(00, 10, 00), scp.RandomizerOffset);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Gets the <see cref="ICachePolicy"/> (as specified via the constructor, or from the centralised <see cref="CachePolicyManager"/> using the <see cref="PolicyKey"/>).
 /// </summary>
 public ICachePolicy GetPolicy() => _policy ?? CachePolicyManager.Get(PolicyKey);