private static void CacheManager_OnRemoveByHandle(object sender, CacheItemRemovedEventArgs e)
 {
     if (e.Reason == CacheItemRemovedReason.Expired)
     {
         //_cacheManager.GetOrAdd(e.Key, e.Region, e.Value);
     }
 }
Exemple #2
0
 internal void AddCall(CacheItemRemovedEventArgs args, params string[] validKeys)
 {
     Guard.NotNullOrEmpty(validKeys, nameof(validKeys));
     if (validKeys.Contains(args.Key))
     {
         Calls++;
         Keys.Add(args.Key);
         if (!string.IsNullOrWhiteSpace(args.Region))
         {
             Regions.Add(args.Region);
         }
     }
 }
Exemple #3
0
            public async Task <CacheItemRemovedEventArgs> RunTest(ICacheManagerConfiguration configuration, string useKey, string useRegion, bool endGetShouldBeNull = true, bool runGetWhileWaiting = true)
            {
                var triggered = false;
                CacheItemRemovedEventArgs resultArgs = null;

                var cache = new BaseCacheManager <string>(configuration);

                cache.OnRemoveByHandle += (sender, args) =>
                {
                    triggered  = true;
                    resultArgs = args;
                };

                if (useRegion == null)
                {
                    cache.Add(useKey, "value");
                    cache.Get(useKey).Should().NotBeNull();
                }
                else
                {
                    cache.Add(useKey, "value", useRegion);
                    cache.Get(useKey, useRegion).Should().NotBeNull();
                }

                // sys runtime checks roughly every 10 seconds, there is no other way to test this quicker I think
                var count = 0;

                while (count < 30 && !triggered)
                {
                    if (runGetWhileWaiting)
                    {
                        if (useRegion == null)
                        {
                            cache.CacheHandles.ToList().ForEach(p => p.Get(useKey));
                        }
                        else
                        {
                            cache.CacheHandles.ToList().ForEach(p => p.Get(useKey, useRegion));
                        }
                    }

                    await Task.Delay(1000);

                    count++;
                }

                if (!triggered)
                {
                    throw new Exception("Waited pretty long, no events triggered...");
                }

                // validate on Up update mode, the handles above have been cleaned up for example
                if (endGetShouldBeNull)
                {
                    if (useRegion == null)
                    {
                        cache.Get(useKey).Should().BeNull();
                    }
                    else
                    {
                        cache.Get(useKey, useRegion).Should().BeNull();
                    }
                }

                return(resultArgs);
            }
 private void OnRemoveByHandle(object sender, CacheItemRemovedEventArgs e)
 {
     Update(CacheEvent.ReH, e.Key);
 }
Exemple #5
0
 private void OnRemoveByHandle(object sender, CacheItemRemovedEventArgs e)
 {
     Update(CacheEvent.ReH, e.Key, CacheActionEventArgOrigin.Local);
 }