How the cache is stored

AAlerin10/16/2022
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)
AAlerin10/16/2022
Which is better, storage in ram or e.g. redis? The app isn't big, just one server.
AAlerin10/16/2022
https://github.com/dotnetcore/EasyCaching
Anyone using this? Is it better than Microsoft's default?
Ppox10/16/2022
most of the time we just use MemoryCache
AAlerin10/16/2022
right?
Ppox10/16/2022
Yeah, just services.AddMemoryCache(); then you can inject IMemoryCache
AAlerin10/16/2022
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.
Ppox10/16/2022
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
Ppox10/16/2022
You can remove stuff but you need a key as you stated.
AAlerin10/17/2022
Anyone know how to make multiple keys? Apparently it's called a tag
Mmtreit10/17/2022
Not sure what you mean
AAlerin10/18/2022
I found a similar problem here.
AAlerin10/18/2022
The point is for one value to have many keys.
AAlerin10/18/2022
in other programming languages this is called tags
AAlerin10/18/2022
Unfortunately, I have searched the documentation and I do not see such an option.
Mmtreit10/18/2022
Can you point to this tag concept in other programming languages?
AAlerin10/18/2022
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 | user@example.com | +11 111 111 111 | John | Smith
search by id 1= John Smith
serch by name User = John Smith
search by mail user@example.com = John Smith
Mmtreit10/18/2022
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.
Mmtreit10/18/2022
And MemoryCache uses a dictionary internally