1- namespace EasyCaching . Demo . ConsoleApp
1+ using System . Threading . Tasks ;
2+
3+ namespace EasyCaching . Demo . ConsoleApp
24{
35 using EasyCaching . Core ;
46 using EasyCaching . SQLite ;
@@ -16,13 +18,13 @@ static void Main(string[] args)
1618 {
1719 option . UseInMemory ( "m1" ) ;
1820
19- //option.UseRedis(config =>
20- //{
21- // config.DBConfig = new Redis.RedisDBOptions { Configuration = "localhost" };
22- // config.SerializerName = "json";
23- //}, "r1");
24-
25-
21+ // option.UseRedis(config =>
22+ // {
23+ // config.DBConfig = new Redis.RedisDBOptions { Configuration = "localhost" };
24+ // config.SerializerName = "json";
25+ // }, "r1");
26+ //
27+
2628 option . UseSQLite ( c =>
2729 {
2830 c . DBConfig = new SQLiteDBOptions
@@ -33,43 +35,51 @@ static void Main(string[] args)
3335 } ;
3436 } , "s1" ) ;
3537
36- //option.WithJson(jsonSerializerSettingsConfigure: x =>
37- //{
38- // x.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.None;
39- //}, "json");
38+ // option.WithJson(jsonSerializerSettingsConfigure: x =>
39+ // {
40+ // x.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.None;
41+ // }, "json");
4042 } ) ;
4143
4244 IServiceProvider serviceProvider = services . BuildServiceProvider ( ) ;
4345 var factory = serviceProvider . GetService < IEasyCachingProviderFactory > ( ) ;
44-
45- //var redisCache = factory.GetCachingProvider("r1");
46-
47- //redisCache.Set<Product>("rkey", new Product() { Name = "test" }, TimeSpan.FromSeconds(20));
48-
49- //var redisVal = redisCache.Get<Product>("rkey");
50-
51- //Console.WriteLine($"redis cache get value, {redisVal.HasValue} {redisVal.IsNull} {redisVal.Value} ");
52-
53-
46+
47+ // var redisCache = factory.GetCachingProvider("r1");
48+ //
49+ // redisCache.Set<Product>("rkey", new Product() { Name = "test" }, TimeSpan.FromSeconds(20));
50+ //
51+ // var redisAllKey = redisCache.GetAllKeysByPrefix("rkey");
52+ //
53+ // var redisVal = redisCache.Get<Product>("rkey");
54+ //
55+ // Console.WriteLine($"redis cache get value, {redisVal.HasValue} {redisVal.IsNull} {redisVal.Value}");
56+
57+
58+
5459 var mCache = factory . GetCachingProvider ( "m1" ) ;
55-
60+
5661 mCache . Set < Product > ( "mkey1" , new Product ( ) { Name = "test" } , TimeSpan . FromSeconds ( 20 ) ) ;
5762
5863 var mVal1 = mCache . Get < Product > ( "mkey1" ) ;
5964
60-
6165 mCache . Set < string > ( "mkey" , "mvalue" , TimeSpan . FromSeconds ( 20 ) ) ;
62-
66+
6367 var mVal = mCache . Get < string > ( "mkey" ) ;
64-
68+
69+ var mAllKey = mCache . GetAllKeysByPrefix ( "mk" ) ;
70+
6571 Console . WriteLine ( $ "in-memory cache get value, { mVal . HasValue } { mVal . IsNull } { mVal . Value } ") ;
6672
73+
6774 var sCache = factory . GetCachingProvider ( "s1" ) ;
6875
76+
6977 sCache . Set < string > ( "skey" , "svalue" , TimeSpan . FromSeconds ( 20 ) ) ;
7078
79+
7180 var sVal = sCache . Get < string > ( "skey" ) ;
7281
82+
7383 Console . WriteLine ( $ "sqlite cache get value, { sVal . HasValue } { sVal . IsNull } { sVal . Value } ") ;
7484
7585 Console . ReadKey ( ) ;
@@ -82,3 +92,4 @@ public class Product
8292 public string Name { get ; set ; }
8393 }
8494}
95+
0 commit comments