-
Notifications
You must be signed in to change notification settings - Fork 4
ICacheManager SetByAbsolute
陈明旭 edited this page Apr 5, 2019
·
2 revisions
Welcome to the Materal wiki!
Home Materal Materal.CacheHelper ICacheManager
设置缓存,到时间后销毁。
参数名 | 类型 | 说明 |
---|---|---|
key | string | 键 |
content | object | 要缓存的对象 |
hours | double | 要缓存的小时数 |
ICacheManager cacheManager = new MemoryCacheManager();
string inputString = Console.ReadLine();
const string cacheKey = "MyKey";
const double saveHours = 1;
cacheManager.SetByAbsolute(cacheKey, inputString, saveHours);
string cacheSaveString = cacheManager.Get<string>(cacheKey);
Console.WriteLine(cacheSaveString);
设置缓存,到时间后销毁。
参数名 | 类型 | 说明 |
---|---|---|
key | string | 键 |
content | object | 要缓存的对象 |
timer | double | 要缓存的时间 |
dateTimeType | DateTimeTypeEnum | 时间类型 |
ICacheManager cacheManager = new MemoryCacheManager();
string inputString = Console.ReadLine();
const string cacheKey = "MyKey";
const double saveTime = 1;
cacheManager.SetByAbsolute(cacheKey, inputString, saveTime, DateTimeTypeEnum.Day);
string cacheSaveString = cacheManager.Get<string>(cacheKey);
Console.WriteLine(cacheSaveString);
Console.ReadKey();
设置缓存,到时间后销毁。
参数名 | 类型 | 说明 |
---|---|---|
key | string | 键 |
content | object | 要缓存的对象 |
date | DateTime | 要缓存的时间 |
ICacheManager cacheManager = new MemoryCacheManager();
string inputString = Console.ReadLine();
const string cacheKey = "MyKey";
DateTime saveTime = DateTime.Now.AddHours(1);
cacheManager.SetByAbsolute(cacheKey, inputString, saveTime);
string cacheSaveString = cacheManager.Get<string>(cacheKey);
Console.WriteLine(cacheSaveString);
Console.ReadKey();
设置缓存,到时间后销毁。
参数名 | 类型 | 说明 |
---|---|---|
key | string | 键 |
content | object | 要缓存的对象 |
timeSpan | TimeSpan | 要缓存的时间段 |
ICacheManager cacheManager = new MemoryCacheManager();
string inputString = Console.ReadLine();
const string cacheKey = "MyKey";
var saveTimeSpan = new TimeSpan(4, 0, 0);
cacheManager.SetByAbsolute(cacheKey, inputString, saveTimeSpan);
string cacheSaveString = cacheManager.Get<string>(cacheKey);
Console.WriteLine(cacheSaveString);
Console.ReadKey();