363 questions
1
vote
2
answers
270
views
IMemoryCache AbsoluteExpirationRelativeToNow not working
I need to store an access token value in memory because it only expires after 24 hours once I get it. So I used memory cache for this.
I first inject IMemoryCache into my service and I added this ...
0
votes
1
answer
269
views
C# ASP.NET MemoryCache grows excessively (23GB instead of 200MB) on one server – potential causes?
I have a ASP.NET application (.NET8) that receives 100 REST calls per minute, each transferring 1MB of data, which is serialized (JSON) and stored in MemoryCache (Microsoft.Extensions.Caching.Memory). ...
0
votes
1
answer
242
views
How do I properly dispose expired objects in MemoryCache (it may still be in used)?
I understand items in MemoryCache are not disposed when expired. I am caching some X509Certificate2 which according to the documentation, should be disposed when done.
However, my naive approach would ...
0
votes
0
answers
96
views
Writing content of MemoryCache to database and race conditions
I am implementing in C# .NET a simple message consumer that reads off a queue a bunch of key, value pair messages and I need to maintain a dictionary of key -> [values seen so far] (this is ...
1
vote
2
answers
44
views
How can I call the DB once, and have the other calls wait on the cache
I have my Blazor server app set up where I cache the AppUser object for the logged in user. It's a pretty heavy read from the DB with 11 queries (using SplitQueries). But once I have it, it then gives ...
0
votes
1
answer
69
views
Sidebar Menu / Index page calling database at the same time error:
I'm running into this error:
InvalidOperationException: A second operation was started on this context instance before a previous operation completed. This is usually caused by different threads ...
3
votes
0
answers
138
views
cache a httpmessage content
I would like to start caching some of the data in web API But I am getting some errors. I am using the HttpContent and storing it in cache using the CacheHelper.SaveTocache. On the next connection I ...
0
votes
1
answer
760
views
Is there a standard way of a simple in-memory caching code in .NET Core?
I have an IHostedService that saves a reference table from the database to cache in .NET Core 6. Meaning, the information saved will not be changed; it's just a reference table. Though there were ...
0
votes
0
answers
104
views
Only three of these PostEvictionCallbacks are fired under the same conditions
I have encountered a strange thing. I have a web api project of .net 6. When IServiceProvider starts, it will use FileService to read data and store it in the cache, and set IChangeToken. If the ...
2
votes
1
answer
697
views
How to lock a google cloud function concurrency?
i want to have a big concurrencies with the cloud function, so I'm using the cloud function v2. But, in one of the steps, I want only 1 process can do it, while other processes need to wait for it.
...
0
votes
0
answers
773
views
C# MemoryCache to store different data type
I'm using Microsoft.Extensions.Caching.Memory, as I hav read it is the newer implementation of System.Runtime.Caching.
I have been reading that it's not recommended to have more than one instances of ...
0
votes
1
answer
1k
views
C# MemoryCache not persisting values
I am attempting to put a wrapper around a repository call, so that the items can be cached.
Here is a cut down overview:
I have an interface for listing categories:
public interface ...
1
vote
1
answer
690
views
Unity Container - How to correctly resolve a parameterised MemoryCache that's registered as a singleton
Despite Unity container being deprecated, unfortunately I find myself having to use it since the current wpf codebase I'm working on has been dependent on it for years.
On the server side, I'm able to ...
2
votes
1
answer
383
views
How to connect Apache Ignite with NestJS?
I'm trying to connect Apache Ignite with Nest JS. I'm getting error regarding the library I used: 'apache-ignite-client'.
Error: TypeError: apache_ignite_client_1.default is not a constructor.
Code
...
18
votes
2
answers
7k
views
Why does IMemoryCache.GetOrCreateAsync return "TItem?" (nullable) instead of "TItem"?
The extension method GetOrCreateAsync for IMemoryCache:
public static async Task<TItem?> GetOrCreateAsync<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, Task<TItem>&...
0
votes
0
answers
259
views
Throttling vulnerability when using cache
I've trying to build a web API throttling mechanism in ASP.NET Core that "penalizes" excess usage in an exponentially-growing denial window e.g. first 3 tries are allowed, 4th is blocked if ...
1
vote
0
answers
465
views
Is Microsoft.Extensions.Caching.Memory thread safe?
According to this doc, Microsoft.Extensions.Caching.Memory is recommended over System.Runtime.Caching/MemoryCache.
System.Runtime.Caching/MemoryCache is thread safe as metioned here. But is Microsoft....
0
votes
0
answers
64
views
ASP .Net Core with MemoryCache
I use MemoryCache with ASP .Net Core. I want to save List<> in cache, but got strange problem.
Forming List;
Succesfully saved it in cache:
TrySetEntity(typeof(SkvBase).Name, _wells, ...
0
votes
1
answer
3k
views
How to store nested lists of objects using MemoryCache in dotnet
I'm trying to find the best way to store complex objects in a MemoryCache (specifically Microsoft.Extensions.Caching.Memory.MemoryCache).
My data's structure would be something as below:
public class ...
0
votes
0
answers
1k
views
IMemoryCache.GetOrCreateAsync returns null
I have a lot of NullReferenceException exceptions on the line if (foosDictionary.TryGetValue(id, out var foo)) and I cannot in any way reproduce the issue.
Stack trace:
System.NullReferenceException: ...
0
votes
1
answer
1k
views
Cons of using MemoryCache as a temporary copy of DB table
I have a site where you can list your car for sale. There is a list and a map with filtering on car types and other car specifications. My idea was to cache cars table and use that to filter on when ...
0
votes
2
answers
2k
views
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 ...
0
votes
1
answer
1k
views
MemoryCache in ASP.NET Core doesn't set elements and acts randomly
I use the MemoryCache library in an ASP.NET Core project to create a cache, following the Microsoft documentation (https://learn.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=...
0
votes
0
answers
668
views
All CacheItems are being removed from MemoryCache at the same time
I am trying to add items to MemoryCache, when adding each item is accompanied by CacheItemPolicy with SlidingExpiration set to 3 seconds.
According to the documentation for SlidingExpiration:
A span ...
1
vote
1
answer
668
views
how use memorycache in this method?
how can i add memorycache in this method ?
this is a section of my code that i want to set memory cache on it.
public IActionResult Index(int pageId = 1, string filter = "",
int ...