private IPackage GetPackage(Func<string, IPackage> openPackage, string path)
{
PackageCacheEntry cacheEntry;
DateTimeOffset lastModified = FileSystem.GetLastModified(path);
// If we never cached this file or we did and it's current last modified time is newer
// create a new entry
if (!_packageCache.TryGetValue(path, out cacheEntry) ||
(cacheEntry != null && lastModified > cacheEntry.LastModifiedTime))
{
// We need to do this so we capture the correct loop variable
string packagePath = path;
// Create the package
IPackage package = openPackage(packagePath);
// create a cache entry with the last modified time
cacheEntry = new PackageCacheEntry(package, lastModified);
if (_enableCaching)
{
// Store the entry
_packageCache[packagePath] = cacheEntry;
_packagePathLookup[new PackageName(package.Id, package.Version)] = path;
}
}
return cacheEntry.Package;
}