Questions tagged [lazycache]
13 questions
8
votes
3 answers
Injecting into constructor with 2 params is not working
I have a ASP .Net Web API controller that I want to take 2 parameters. The first one is an EF context and the second being a caching interface. If I just have the EF context the constructor gets called, but when I add the caching interface I get the…

user441521
- 6,942
- 23
- 88
- 160
4
votes
2 answers
LazyCache: Regularly refresh cached items
I am using LazyCache and want to have cache refreshed e.g. every hour, but ideally I want the first caller after the cache item expired do not wait for cache reloaded. I wrote the following
public async Task
- >>…

Michael Freidgeim
- 26,542
- 16
- 152
- 170
3
votes
2 answers
C# LazyCache concurrent dictionary garbage collection
Been having some problems with a web based .Net(C#) application. I'm using the LazyCache library to cache frequent JSON responses (some in & around 80+KB) for users belonging to the same company across user sessions.
One of the things we need to do…

user805703
- 207
- 6
- 14
1
vote
1 answer
LazyCache concurrent requests return same bad result
I am trying LazyCache in C# and .NET 6.
It is failing one of our tests, so I made a smaller reproduction here.
I expect LazyCache to do a thread safe cache so that one failed request does not impact others.
Specifically, I have set up a…

Anthony
- 5,176
- 6
- 65
- 87
1
vote
1 answer
On Redis cache miss, get data only executes once
We currently use LazyCache in our .NET Core microservice, but want to utilize a distributed cache, so we are looking at a solution with Redis.
I am looking into the cache miss scenario. Let's assume we have 100 requests (on the same server) coming…

Erik Steinebach
- 367
- 2
- 14
1
vote
1 answer
LazyCache: How to prevent specific item to be added to the cache
How to prevent specific items to be added to the cache. In my case I am looking at preventing null returns to be added to the cache. This is what I am doing at the moment:
Func internalGetRecordUri =() =>
{
…

Luis
- 5,979
- 2
- 31
- 51
1
vote
2 answers
Faking an Extension Method in a 3rd Party Library
Have I written an untestable method? As the library I am using has an important method which is implemented as an extension method, it seems like I am unable to fake it. And thus, unable to test my method.
First, I'll set out a truncated version of…

onefootswill
- 3,707
- 6
- 47
- 101
0
votes
1 answer
GetAsync gets high response time in load requests
I am using LazyCache.AspNetCore package from nuget to store some data in memory and read from memory. this is my sample code:
IAppCache cache = new CachingService();
StopWatch _watch;
public async Task TestAsync(UserInfo user){
var key = await…

Nega
- 119
- 8
0
votes
0 answers
How to extend LazyCache with Redis Cache for asp.net core 3.1 application?
I have asp.net core 3.1 web api project which leverages Azure SQL database as its data storage option. At present I am also using Azure Redis Cache to improve performance of the application.
Here goes the code details :
ICacheProvider.cs:
public…

santosh kumar patro
- 7,231
- 22
- 71
- 143
0
votes
2 answers
LazyCache prevent null items being added to cache
I have a method that will expire null items immediately, however I wanted to know if there w as better way to do this for all memory cache items instead of repeating the same code over and over
output = _cache.GetOrAdd("GetRecordUri" + 123, entry…

CodeMan03
- 570
- 3
- 18
- 43
0
votes
1 answer
Lazy Cache mocking GetorAddasync()
My service code is below:
var cachedLatestVersion = await _cache.GetOrAddAsync("latestVersion", latestVersion, DateTimeOffset.Now.AddHours(24));
I have tried to mock the IAppache interface and set up a value for the GetOrAddAsync method but an error…

Mery
- 3
- 2
0
votes
1 answer
How to use LazyCache with async function that takes parameter
I am trying to use LazyCache. The api has GetOrAddAsync that takes Func>. This is the function that build stuff i want to cache.
However the function that i have takes input parameter. The signature of my function is Func>
So as…

LP13
- 30,567
- 53
- 217
- 400
0
votes
3 answers
how to use async method inside lock
I have CacheService that stores a collection in the MemoryCache and then finds an element from the collection that is stored in the cache. Given the multi threaded environment i want to make sure only one Worker can store the collection in the cache…

LP13
- 30,567
- 53
- 217
- 400