Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

cache.TryGetValue in MemoryCache c# .net

public class MyCache
{
  private MemoryCache _cache = new MemoryCache(new MemoryCacheOptions());
  private string nullValue = Guid.NewGuid().ToString();

  public void Set(string cacheKey, string toSet)
    => _cache.Set<string>(cacheKey, toSet == null ? nullValue : toSet);

  public string Get(string cacheKey)
  {
    var isInCache = _cache.TryGetValue(cacheKey, out string cachedVal);
    if (!isInCache) return null;

    return cachedVal == nullValue ? null : cachedVal;
  }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity recttransform set anchor 
Csharp :: vb.net single quote in string 
Csharp :: Permutation and Combination in C# 
Csharp :: C# Read Excel columns header return to list 
Csharp :: c# webclient ssl bypass 
Csharp :: C# .net JwtSecurityTokenHandler jwttoken claims to object 
Csharp :: C# today, yesterday, last week, last month 
Csharp :: windows form toolbox enter key 
Csharp :: c# xamarin forms use AssetManager to get text file 
Csharp :: c# convert datatable to csv 
Csharp :: c# hashset 
Csharp :: unity bool to int 
Csharp :: c# windows service .net core 
Csharp :: c# array backwards 
Csharp :: insert variables into a string C# 
Csharp :: leantween move ui 
Csharp :: out variable in c# 
Csharp :: unity error cs1656 
Csharp :: how to use K2 games Games parallax background 
Csharp :: syoutube 
Html :: html 5 default code 
Html :: htmjl favicons 
Html :: free video url for testing 
Html :: Add Random Image from Web in html 
Html :: center vertically and horizontally bootstrap 4 
Html :: how to make links open in a new window 
Html :: html video hide controls 
Html :: html starter 
Html :: adding mp4 in html 
Html :: html horizontal line style 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =