Skip to content

Instantly share code, notes, and snippets.

@ntakouris
Created August 29, 2019 22:00
Show Gist options
  • Save ntakouris/9005c086bb9108c7e8a699490a020392 to your computer and use it in GitHub Desktop.
Save ntakouris/9005c086bb9108c7e8a699490a020392 to your computer and use it in GitHub Desktop.
public async Task CacheResponseAsync(string cacheKey, object response, TimeSpan timeTimeLive)
{
if (response == null)
{
return;
}
var serializedResponse = JsonConvert.SerializeObject(response);
await _distributedCache.SetStringAsync(cacheKey, serializedResponse, new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = timeTimeLive
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment