Asp.net 即使在使用文件依赖项插入之后,也不会存储缓存项

Asp.net 即使在使用文件依赖项插入之后,也不会存储缓存项,asp.net,caching,Asp.net,Caching,我正在尝试使用cache.Insert()在缓存中存储字符串。当我尝试使用文件依赖关系存储它时,在Cache.Insert()之后,我的缓存值仍然为null。请帮我解决这个问题。此外,此代码位于页面加载函数中。 下面是我的缓存代码: // add 30secs expiration timer DateTime time = DateTime.Today.AddSeconds(30); // add file dependency for a file CacheDependency que

我正在尝试使用cache.Insert()在缓存中存储字符串。当我尝试使用文件依赖关系存储它时,在Cache.Insert()之后,我的缓存值仍然为null。请帮我解决这个问题。此外,此代码位于页面加载函数中。 下面是我的缓存代码:

// add 30secs expiration timer
 DateTime time = DateTime.Today.AddSeconds(30);

// add file dependency for a file
CacheDependency quesDependency = new CacheDependency(filePath, time);

Cache.Insert("question_of_the_day", html, quesDependency,time, Cache.NoSlidingExpiration);

// after this step i still get Cache["question_of_the_day"] = null instead of getting that html string.

您使用的绝对过期时间不正确

DateTime.Today - An object that is set to today's date, with the time component set to 00:00:00.

改变

DateTime time = DateTime.Today.AddSeconds(30);

DateTime time = DateTime.Now.AddSeconds(30);