42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using ZiggyCreatures.Caching.Fusion;
|
|
|
|
namespace MyFunctioncache
|
|
{
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
var entryOptions = new FusionCacheEntryOptions().SetDuration(TimeSpan.FromMinutes(10));
|
|
|
|
// 创建缓存实例
|
|
var cache = new FusionCache(new FusionCacheOptions()
|
|
{
|
|
DefaultEntryOptions = new FusionCacheEntryOptions
|
|
{
|
|
Duration = TimeSpan.FromMinutes(5) // 默认缓存5分钟
|
|
}
|
|
});
|
|
// 设置缓存值
|
|
cache.Set("product_123", new PersonInfo {UserName="aaa"});
|
|
|
|
// 获取缓存值
|
|
var product = cache.TryGet<PersonInfo>("product_123");
|
|
|
|
// 删除缓存项
|
|
cache.Remove("product_123");
|
|
Console.WriteLine("Hello, World!");
|
|
}
|
|
}
|
|
|
|
public class PersonInfo
|
|
{
|
|
public string UserName { get; set; }
|
|
|
|
public int Age { get; set; }
|
|
|
|
public string Nationality { get; set; }
|
|
|
|
public string CacheMsg { get; set; }
|
|
}
|
|
}
|