'How to setup In memory cache for RestSharp Client in .NET Core Console Application

I have C# console application in .NET 6.

I am researching the setup of a RestSharp client first i need to setup in memory caching. I have done an implementation in asp.net that uses System.Runtime.Caching

Example of the difference :

  public class InMemoryCache : ICacheService
  {
    public T Get<T>(string cacheKey) where T : class
    {
        return MemoryCache.Default.Get(cacheKey) as T;
    }

the MemoryCache.Default is not part of the Extension Library Microsoft.Extensions.Caching.Memory like the However with the console application with .NET 6 I have to use Microsoft.Extensions.Caching.Memory

How would i implement the above with using Microsoft.Extensions.Caching.Memory

Also here is my configuration

 //class Program
 private static InMemoryCache _cache;

 //Main

 services.AddMemoryCache();
 var serviceProvider = services.BuildServiceProvider();
 _cache = serviceProvider.GetService<InMemoryCache>();


Sources

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

Source: Stack Overflow

Solution Source