C
C#3y ago
Alerin

How the cache is stored

Hi, what kind of cache library do you use? How to solve the problem of multiple keys? Here is a similar problem: https://stackoverflow.com/questions/59103206/how-to-cache-an-object-with-multiple-keys-in-c-sharp The solution is interesting, but it makes the cache constant and can overflow (no expiry date of the item)
Stack Overflow
How to cache an object with multiple keys in C#
I have models that are unique in 2 or more properties. For example, objects of the class Entity are unique both by name and by ID. public class Entity { public int Id { get; set; } public
15 Replies
Alerin
AlerinOP3y ago
Which is better, storage in ram or e.g. redis? The app isn't big, just one server.
Alerin
AlerinOP3y ago
https://github.com/dotnetcore/EasyCaching Anyone using this? Is it better than Microsoft's default?
GitHub
GitHub - dotnetcore/EasyCaching: EasyCaching is an open source cach...
:boom: EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier! - GitHub - dotnetcore/EasyCachin...
pox
pox3y ago
most of the time we just use MemoryCache
Alerin
AlerinOP3y ago
right?
pox
pox3y ago
Yeah, just services.AddMemoryCache(); then you can inject IMemoryCache
Alerin
AlerinOP3y ago
Is it possible to clear the cache? I used to test it but without a key I had a problem with it. I had to restart the application to clear the cache.
pox
pox3y ago
Unsure, never had to clear the whole cache. I guess you could wrap the cache and add a set of keys and clear if needed but feels hacky You can remove stuff but you need a key as you stated.
Alerin
AlerinOP3y ago
Anyone know how to make multiple keys? Apparently it's called a tag
mtreit
mtreit3y ago
Not sure what you mean
Alerin
AlerinOP3y ago
Stack Overflow
How to cache an object with multiple keys in C#
I have models that are unique in 2 or more properties. For example, objects of the class Entity are unique both by name and by ID. public class Entity { public int Id { get; set; } public
Alerin
AlerinOP3y ago
I found a similar problem here. The point is for one value to have many keys. in other programming languages this is called tags Unfortunately, I have searched the documentation and I do not see such an option.
mtreit
mtreit3y ago
Can you point to this tag concept in other programming languages?
Alerin
AlerinOP3y ago
Just looking, can't find it right now. I saw in node and PHP that there are "tags" Thanks to this, you can have many keys, for example: There is a user, has an ID, Name, E-mail, telephone number and full name You can search for it by ID, Name, E-mail and Phone e.g. 1 | User | [email protected] | +11 111 111 111 | John | Smith search by id 1= John Smith serch by name User = John Smith search by mail [email protected] = John Smith
mtreit
mtreit3y ago
Well if you are willing to do a linear search you can obviously search for objects by any property. If you want an efficient search there are a variety of options (for instance, keep the data sorted and do a binary search, or build some kind of index) but for something like a dictionary (which is based on hash tables) there is no magic way to do a fast lookup on multiple different properties - that's not how hash tables work. And MemoryCache uses a dictionary internally
Want results from more Discord servers?
Add your server