Example #1
0
        public void Put_should_put_item_using_passed_sliding_ttl_zero()
        {
#if PORTABLE
            MemoryCacheImplementation memoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());
#else
            MemoryCacheImplementation memoryCache = System.Runtime.Caching.MemoryCache.Default;
#endif

            string key   = "anything";
            object value = new object();

            MemoryCacheProvider provider = new MemoryCacheProvider(memoryCache);

            TimeSpan minExpiration =
#if PORTABLE
                TimeSpan.FromMilliseconds(1) // This is the minimum permitted sliding ttl for .NetStandard
#else
                TimeSpan.Zero
#endif
            ;

            Ttl ttl = new Ttl(minExpiration, false);
            provider.Put(key, value, ttl);

            Thread.Sleep(TimeSpan.FromMilliseconds(10));

#if PORTABLE
            object got;
            memoryCache.TryGetValue(key, out got);
#else
            object got = memoryCache[key];
#endif
            got.Should().BeNull();
        }
Example #2
0
 public ReportController(IOptions <AppSettings> settings, Microsoft.Extensions.Caching.Memory.IMemoryCache memoryCache,
                         Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment)
 {
     _cache = memoryCache;
     _hostingEnvironment = hostingEnvironment;
     _connection         = settings.Value.PersistanceConnectionString;
 }
Example #3
0
        public void Put_should_put_item_using_passed_sliding_ttl_maxvalue()
        {
#if PORTABLE
            MemoryCacheImplementation memoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());
#else
            MemoryCacheImplementation memoryCache = System.Runtime.Caching.MemoryCache.Default;
#endif

            string key   = "anything";
            object value = new object();

            MemoryCacheProvider provider = new MemoryCacheProvider(memoryCache);

            TimeSpan maxSlidingExpiration =
#if PORTABLE
                TimeSpan.MaxValue
#else
                TimeSpan.FromDays(365) // This is the maximum permitted sliding ttl for .NetFramework4.0 and 4.5 MemoryCache.
#endif
            ;

            Ttl ttl = new Ttl(maxSlidingExpiration, true);
            provider.Put(key, value, ttl);

#if PORTABLE
            object got;
            memoryCache.TryGetValue(key, out got);
#else
            object got = memoryCache[key];
#endif
            got.Should().BeSameAs(value);
        }
Example #4
0
        public void Put_should_put_item_using_passed_sliding_ttl()
        {
#if PORTABLE
            MemoryCacheImplementation memoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());
#else
            MemoryCacheImplementation memoryCache = System.Runtime.Caching.MemoryCache.Default;
#endif

            TimeSpan shimTimeSpan = TimeSpan.FromSeconds(1); // If test fails transiently in different environments, consider increasing shimTimeSpan.

            string key   = "anything";
            object value = new object();

            // Place an item in the cache that should last for only 2x shimTimespan
            MemoryCacheProvider provider = new MemoryCacheProvider(memoryCache);
            Ttl ttl = new Ttl(shimTimeSpan + shimTimeSpan, true);
            provider.Put(key, value, ttl);

            // Prove that we can repeatedly get it from the cache over a 5x shimTimespan period, due to repeated access.

            for (int i = 0; i < 5; i++)
            {
#if PORTABLE
                object got;
                memoryCache.TryGetValue(key, out got);
#else
                object got = memoryCache[key];
#endif

                got.Should().BeSameAs(value, $"at iteration {i}");

                Thread.Sleep(shimTimeSpan);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MemoryCacheProvider"/> class.
 /// </summary>
 /// <param name="memoryCache">The memory cache instance in which to store cached items.</param>
 public MemoryCacheProvider(MemoryCacheImplementation memoryCache)
 {
     if (memoryCache == null)
     {
         throw new ArgumentNullException(nameof(memoryCache));
     }
     _cache = memoryCache;
 }
        public ReportDesignerAPIController(Microsoft.Extensions.Caching.Memory.IMemoryCache memoryCache, Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment)
        {
            _cache = memoryCache;
            _hostingEnvironment = hostingEnvironment;
            ExternalServer externalServer = new ExternalServer(_hostingEnvironment);

            ReportDesignerHelper.ReportingServer = externalServer;
        }
Example #7
0
 public ReportMovimentacaoController(Microsoft.Extensions.Caching.Memory.IMemoryCache memoryCache,
                                     Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment, IReportRepository repository, IConfiguration configuration)
 {
     _cache = memoryCache;
     _hostingEnvironment = hostingEnvironment;
     _repository         = repository;
     _config             = configuration;
 }
Example #8
0
        public static string Tables(this Microsoft.Extensions.Caching.Memory.IMemoryCache cacheIn, CacheKey key)
        {
            switch (key)
            {
            case CacheKey.Users: return("UserTable");

            default: return(string.Empty);
            }
        }
Example #9
0
        public void Get_should_return_null_on_unknown_key()
        {
#if PORTABLE
            MemoryCacheImplementation memoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());
#else
            MemoryCacheImplementation memoryCache = System.Runtime.Caching.MemoryCache.Default;
#endif

            MemoryCacheProvider provider = new MemoryCacheProvider(memoryCache);
            object got = provider.Get(Guid.NewGuid().ToString());
            got.Should().BeNull();
        }
Example #10
0
        public void Should_not_throw_when_MemoryCacheImplementation_is_not_null()
        {
#if PORTABLE
            MemoryCacheImplementation memoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());
#else
            MemoryCacheImplementation memoryCache = System.Runtime.Caching.MemoryCache.Default;
#endif

            Action configure = () => new MemoryCacheProvider(memoryCache);

            configure.ShouldNotThrow();
        }
Example #11
0
 public CacheableResults(TimeSpan ts = default(TimeSpan))
 {
     if (ts == default(TimeSpan))
     {
         ts = TimeSpan.FromMinutes(15);
     }
     memoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions()
     {
     });
     memoryCacheProvider = new Polly.Caching.Memory.MemoryCacheProvider(memoryCache);
     cachePolicy         = Polly.Policy.Cache(memoryCacheProvider, ts);
     cachePolicyAsync    = Polly.Policy.CacheAsync(memoryCacheProvider, ts);
 }
Example #12
0
        // services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
        // services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();

        public MyImageTagHelper(
            Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment,
            Microsoft.Extensions.Caching.Memory.IMemoryCache cache,
            Microsoft.AspNetCore.Http.IHttpContextAccessor httpContextAccessor,
            Microsoft.AspNetCore.Mvc.Infrastructure.IActionContextAccessor actionContextAccessor,
            // For base constructor
            System.Text.Encodings.Web.HtmlEncoder htmlEncoder,
            Microsoft.AspNetCore.Mvc.Routing.IUrlHelperFactory urlHelperFactory
            )
            : base(urlHelperFactory, htmlEncoder)
        {
            this.HostingEnvironment = hostingEnvironment;
            this.Cache         = cache;
            this.HttpContext   = httpContextAccessor.HttpContext;
            this.ActionContext = actionContextAccessor.ActionContext;
        }
Example #13
0
        public void Put_should_put_item_using_passed_nonsliding_ttl()
        {
#if PORTABLE
            MemoryCacheImplementation memoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());
#else
            MemoryCacheImplementation memoryCache = System.Runtime.Caching.MemoryCache.Default;
#endif

            TimeSpan shimTimeSpan = TimeSpan.FromSeconds(0.1); // If test fails transiently in different environments, consider increasing shimTimeSpan.

            string key   = "anything";
            object value = new object();

            MemoryCacheProvider provider = new MemoryCacheProvider(memoryCache);
            Ttl ttl = new Ttl(shimTimeSpan, false);
            provider.Put(key, value, ttl);

            // Initially (before ttl expires), should be able to get value from cache.
#if PORTABLE
            object got;
            memoryCache.TryGetValue(key, out got);
#else
            object got = memoryCache[key];
#endif
            got.Should().BeSameAs(value);

            // Wait until the TTL on the cache item should have expired.
            Thread.Sleep(shimTimeSpan + shimTimeSpan);

#if PORTABLE
            memoryCache.TryGetValue(key, out got);
#else
            got = memoryCache[key];
#endif

            got.Should().NotBeSameAs(value);
            got.Should().BeNull();
        }
Example #14
0
        public void Put_should_put_item_using_passed_nonsliding_ttl_maxvalue()
        {
#if PORTABLE
            MemoryCacheImplementation memoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());
#else
            MemoryCacheImplementation memoryCache = System.Runtime.Caching.MemoryCache.Default;
#endif

            string key   = "anything";
            object value = new object();

            MemoryCacheProvider provider = new MemoryCacheProvider(memoryCache);
            Ttl ttl = new Ttl(TimeSpan.MaxValue, false);
            provider.Put(key, value, ttl);

#if PORTABLE
            object got;
            memoryCache.TryGetValue(key, out got);
#else
            object got = memoryCache[key];
#endif
            got.Should().BeSameAs(value);
        }
Example #15
0
        public void Get_should_return_instance_previously_stored_in_cache()
        {
#if PORTABLE
            MemoryCacheImplementation memoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());
#else
            MemoryCacheImplementation memoryCache = System.Runtime.Caching.MemoryCache.Default;
#endif

            string key   = "anything";
            object value = new object();
#if PORTABLE
            using (Microsoft.Extensions.Caching.Memory.ICacheEntry entry = memoryCache.CreateEntry(key)) {
                entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(10);
                entry.Value = value;
            }
#else
            memoryCache[key] = value;
#endif

            MemoryCacheProvider provider = new MemoryCacheProvider(memoryCache);
            object got = provider.Get(key);
            got.Should().BeSameAs(value);
        }
        public void Put_should_put_item_into_configured_MemoryCacheImplementation()
        {
#if PORTABLE
            MemoryCacheImplementation memoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());
#else
            MemoryCacheImplementation memoryCache = System.Runtime.Caching.MemoryCache.Default;
#endif

            string key   = Guid.NewGuid().ToString();
            object value = new object();

            MemoryCacheProvider provider = new MemoryCacheProvider(memoryCache);
            Ttl ttl = new Ttl(TimeSpan.FromSeconds(10));
            provider.Put(key, value, ttl);

#if PORTABLE
            object got;
            memoryCache.TryGetValue(key, out got);
#else
            object got = memoryCache[key];
#endif

            got.Should().BeSameAs(value);
        }
 public MemoryResponseCache(Microsoft.Extensions.Caching.Memory.IMemoryCache cache)
 {
 }
 public ActionWorkflowRunHandler(Services.IGitHubClientFactory gitHubClientFactory, Microsoft.Extensions.Caching.Memory.IMemoryCache cache, Microsoft.Extensions.Logging.ILogger logger)
     : base(gitHubClientFactory, cache, logger)
 {
 }
Example #19
0
 public MemoryCache(Microsoft.Extensions.Caching.Memory.IMemoryCache cache)
 {
     this.keys   = new List <string>();
     this._cache = cache;
 }
 public IssueCommentEditDeleteHandler(Services.IGitHubClientFactory gitHubClientFactory, Microsoft.Extensions.Caching.Memory.IMemoryCache cache, Microsoft.Extensions.Logging.ILogger logger)
     : base(gitHubClientFactory, cache, logger)
 {
 }
 public static bool TryGetValue <TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, out TItem value)
 {
     throw null;
 }
 public static TItem Set <TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, System.TimeSpan absoluteExpirationRelativeToNow)
 {
     throw null;
 }
 public static TItem Set <TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, Microsoft.Extensions.Primitives.IChangeToken expirationToken)
 {
     throw null;
 }
 public static TItem Set <TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options)
 {
     throw null;
 }
 public static TItem Get <TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key)
 {
     throw null;
 }
 public static TItem GetOrCreate <TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, System.Func <Microsoft.Extensions.Caching.Memory.ICacheEntry, TItem> factory)
 {
     throw null;
 }
 public static System.Threading.Tasks.Task <TItem> GetOrCreateAsync <TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, System.Func <Microsoft.Extensions.Caching.Memory.ICacheEntry, System.Threading.Tasks.Task <TItem> > factory)
 {
     throw null;
 }
Example #28
0
 public TestHandler(Services.IGitHubClientFactory gitHubClientFactory, Microsoft.Extensions.Caching.Memory.IMemoryCache cache)
     : base(gitHubClientFactory, cache, NullLogger.Instance)
 {
 }
 // Post action to process the report from server based json parameters and send the result back to the client.
 public ReportViewerWebApiController(Microsoft.Extensions.Caching.Memory.IMemoryCache memoryCache,
                                     Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment)
 {
     _cache = memoryCache;
     _hostingEnvironment = hostingEnvironment;
 }
 public static TItem Set <TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, System.DateTimeOffset absoluteExpiration)
 {
     throw null;
 }