Skip to content

Extensions

Furkan Güngör edited this page Jan 2, 2021 · 1 revision

EasyCache.Core.Extensions

This folder in EasyCache.Core includes GetAndSet method.

What GetAndSet method?

With this extension, the Get and Set methods work in pairs. If the cache is null, the given Func <T> will run and cached.

Sample

[HttpGet("[controller]/category")]
public async Task<IActionResult> CategoryAsync()
{
    var data = await easyCacheService.GetAndSet("getAndSet", () => GetData(), TimeSpan.FromSeconds(1));
    return Ok(data);
}
Clone this wiki locally