SqlSugar/Src/Asp.NetCore2/CacheTest/Program.cs
2023-10-24 18:06:15 +08:00

44 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using SqlSugar;
using System;
namespace CacheTest
{
class Program
{
static void Main(string[] args)
{
SugarCache cache = new SugarCache();
cache.Add("a", "1");
var x = cache.Get<string>("a");
cache.Add("a2", "11",5);
var x2 = cache.Get<string>("a2");
var isa= cache.ContainsKey<string>("a2");
var allKeys = cache.GetAllKey<string>();
var testr=cache.GetOrCreate<string>("a33",()=> { return "aaa"; },10);
cache.Remove<string>("aaaaaaaa");
cache.Remove<string>("a");
ICacheService myCache = cache;
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = "server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST",
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
MoreSettings=new ConnMoreSettings() {
IsAutoRemoveDataCache = true,
},
ConfigureExternalServices = new ConfigureExternalServices()
{
DataInfoCacheService = myCache //配置我们创建的缓存类具体用法看标题5
}
});
db.Fastest<Order>().BulkCopy(new System.Collections.Generic.List<Order>()
{
new Order(){ CreateTime=DateTime.Now, CustomId=1, Name="a" }
});
Console.WriteLine("Hello World!");
}
}
}