memorycache

Memory Cache .Net 4.0 performance test : astonishing result

我是研究僧i 提交于 2020-01-27 20:56:58
问题 This performance test is wrong or the system cache is working with exceptional performance? This is my result : [13] number of interactions 100000 : 63 milliseconds [14] number of interactions 100000 : 139 milliseconds [12] number of interactions 100000 : 47 milliseconds [15] number of interactions 100000 : 44 milliseconds End of test. Hardware : x86 Family 6 Model 23 Stepping GenuineIntel ~2992 Mhz 3.327 MB, 5.1.2600 Service Pack 3 using System; using System.Collections.Generic; using System

Memory Cache .Net 4.0 performance test : astonishing result

放肆的年华 提交于 2020-01-27 20:54:06
问题 This performance test is wrong or the system cache is working with exceptional performance? This is my result : [13] number of interactions 100000 : 63 milliseconds [14] number of interactions 100000 : 139 milliseconds [12] number of interactions 100000 : 47 milliseconds [15] number of interactions 100000 : 44 milliseconds End of test. Hardware : x86 Family 6 Model 23 Stepping GenuineIntel ~2992 Mhz 3.327 MB, 5.1.2600 Service Pack 3 using System; using System.Collections.Generic; using System

How to clear MemoryCache in ASP.NET Core?

梦想的初衷 提交于 2020-01-15 10:15:32
问题 How to correctly clear IMemoryCache from ASP.NET Core? I believe this class is missing Clear method, but anyway how to deal with it? In my project I'm caching DocumentRepository's methods for 24 hours where I'm getting lots of rows from database. But sometimes I can change the database, so I want to clear the IMemoryCache as it has got rubbish data. 回答1: The cache class and interface don't have any methods for clearing neither ones to iterate over the keys, since it's not meant to be a list

MemoryCache.Default not available in .NET Core?

风格不统一 提交于 2020-01-14 07:04:09
问题 I'm porting some code from .NET 4.6 til .NET Core and have run into some problems with MemoryCache. The 4.6 code is using MemoryCache.Default to instantiate the cache, but this doesn't seem to be available in .NET Core. Is there any equivalent to this in .NET Core or should I rather new up my own MemoryCache as a singleton and inject it via IOC? 回答1: Generally you would use the singleton IMemoryCache IServiceProvider ConfigureServices(IServiceCollection services){ ... services.AddMemoryCache(

Memory Cache in web api

别说谁变了你拦得住时间么 提交于 2020-01-10 14:46:43
问题 I was looking for Caching in my web api where i can use output of one api method(that changes once in 12hrs) for subsequesnt calls and then i found this solution on SO,but i am having a difficulty in understanding and using the below code private IEnumerable<TEntity> GetFromCache<TEntity>(string key, Func<IEnumerable<TEntity>> valueFactory) where TEntity : class { ObjectCache cache = MemoryCache.Default; var newValue = new Lazy<IEnumerable<TEntity>>(valueFactory); CacheItemPolicy policy = new

Memory Cache in web api

霸气de小男生 提交于 2020-01-10 14:45:07
问题 I was looking for Caching in my web api where i can use output of one api method(that changes once in 12hrs) for subsequesnt calls and then i found this solution on SO,but i am having a difficulty in understanding and using the below code private IEnumerable<TEntity> GetFromCache<TEntity>(string key, Func<IEnumerable<TEntity>> valueFactory) where TEntity : class { ObjectCache cache = MemoryCache.Default; var newValue = new Lazy<IEnumerable<TEntity>>(valueFactory); CacheItemPolicy policy = new

MemoryCache with regions support?

若如初见. 提交于 2020-01-02 00:43:25
问题 I need to add cache functionality and found a new shiny class called MemoryCache. However, I find MemoryCache a little bit crippled as it is (I'm in need of regions functionality). Among other things I need to add something like ClearAll(region). Authors made a great effort to keep this class without regions support, code like: if (regionName != null) { throw new NotSupportedException(R.RegionName_not_supported); } flies in almost every method. I don't see an easy way to override this

Using multiple instances of MemoryCache

梦想的初衷 提交于 2019-12-28 03:33:05
问题 I'd like to add caching capabilities to my application using the System.Runtime.Caching namespace, and would probably want to use caching in several places and in different contexts. To do so, I want to use several MemoryCache instances. However, I see here that using more than one instance of MemoryCache is discouraged: MemoryCache is not a singleton, but you should create only a few or potentially only one MemoryCache instance and code that caches items should use those instances. How would

A second operation started on this context before a previous operation completed

六月ゝ 毕业季﹏ 提交于 2019-12-24 05:47:05
问题 I have a project with asp.net core and entity framework core, for performance reasons I use MemoryCache. ForumQueryManager class is for querying forum data and this class for data use CacheManager Get method and pass cachekey and timeout cache time and a method for when cache is empty for retrieving data from database. this code work almost always. but sometimes throw exception Exception: An unhandled exception occurred while processing the request. InvalidOperationException: A second

How to iterate through MemoryCache in asp.net core?

孤者浪人 提交于 2019-12-23 17:24:30
问题 There's no available method in IMemoryCache that allows to iterate through each cached item. My project is small, I don't want to use other options like Redis. namepsace Microsoft.Extensions.Caching.Memory{ public static class CacheExtensions { public static object Get(this IMemoryCache cache, object key); public static TItem Get<TItem>(this IMemoryCache cache, object key); public static TItem GetOrCreate<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, TItem> factory);