'How do I store the result as cache in C# [closed]

So I have below code running, where I am calling an Api, which gives me result a Json Array which I am later querying in my code. The response, I get from the api is mostly constant and since it has SOME data, it takes few seconds to get the complete result. I would like to know, if I can store the result coming from api in some way in cache in order to make the whole processing part faster?

EDIT: below code is inside a Foreach loop

foreach (var did in myDeserializedClass)
 {
  if (did.id == matchedid)
   {
     url = "https://.../api/information/test";
     var response = await Request(Stream.Null, url, "GET");
     string message = await response.Content.ReadAsStringAsync();
     var allcodes = JsonConvert.DeserializeObject<List<CoCode>>(message);
     foreach(var cc in allcodes )
    {....// rest of my code


Solution 1:[1]

You can absolutely use a memory cache, even Microsoft provide one which if possible also can be place in the api side for quicker lookups

https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.memory.memorycache?view=dotnet-plat-ext-6.0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 T. Nielsen