初始化
This commit is contained in:
14
MyFunctioncache/MyFunctioncache.csproj
Normal file
14
MyFunctioncache/MyFunctioncache.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ZiggyCreatures.FusionCache" Version="2.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
41
MyFunctioncache/Program.cs
Normal file
41
MyFunctioncache/Program.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
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; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user