我在代码中的一些列表中记录了一些数据,我想在每天晚上11点重置列表的索引,而不删除前一天的数据。
有办法吗?
谢谢
int startTime = ToTime(23, 0, 0);
if (ToTime(Time[0]) >= startTime)
{
// Not resetting the data indexes, but accumulating the current day indexes over the previous day's
indexes
}
我会改用System.Runtime.Caching.MemoryCache
。
var memCache = MemoryCache.Default; // or new MemoryCache(cacheName);
memCache.Set("myCacheKeyWithIndex", myObjectToStore, DateTimeOffset.UtcNow.AddHours(24));
// to retrieve an item
var myObjFromCache = memCache.Get("myCacheKeyWithIndex") as MyObject;
在这种情况下,该项目将在24小时后自动删除。使用MemoryCache的另一个优点是此集合已经是ThreadSafe。