在ASP.NET中,我想在缓存中存储一个对象,该对象依赖于特定文件夹及其子文件夹中的所有文件.只是添加依赖于根文件夹的对象不起作用.除了在所有文件上创建一系列依赖项之外,是否有任何合理的方法可以做到这一点?
我相信您可以滚动自己的缓存依赖项并使用FileSystemMonitor来监视文件系统更改.
更新:以下示例代码
public class FolderCacheDependency : CacheDependency { public FolderCacheDependency(string dirName) { FileSystemWatcher watcher = new FileSystemWatcher(dirName); watcher.Changed += new FileSystemEventHandler(watcher_Changed); watcher.Deleted += new FileSystemEventHandler(watcher_Changed); watcher.Created += new FileSystemEventHandler(watcher_Changed); watcher.Renamed += new RenamedEventHandler(watcher_Renamed); } void watcher_Renamed(object sender, RenamedEventArgs e) { this.NotifyDependencyChanged(this, e); } void watcher_Changed(object sender, FileSystemEventArgs e) { this.NotifyDependencyChanged(this, e); } }