/// <summary> /// Gets the group with the given key. /// </summary> /// <param name="key">The key, nor null.</param> /// <returns>The cache group.</returns> protected virtual IDiskCacheGroup GetGroup(string key) { var hash = new Hash64(); hash = hash.Add(key); string path = Path.Combine(cacheDirectoryPath, hash.ToString()); return new Group(this, key, new DirectoryInfo(path)); }
/// <summary> /// Gets the group with the given key. /// </summary> /// <param name="key">The key, nor null.</param> /// <returns>The cache group.</returns> protected virtual IDiskCacheGroup GetGroup(string key) { var hash = new Hash64(); hash = hash.Add(key); string path = Path.Combine(cacheDirectoryPath, hash.ToString()); return(new Group(this, key, new DirectoryInfo(path))); }
/// <inheritdoc /> protected override void LoadPlugins(PluginCallback pluginCallback, IProgressMonitor progressMonitor) { // Attempt to read the old cache. string cacheFilePath; try { Hash64 hash = new Hash64(); foreach (string pluginPath in PluginPaths) { hash = hash.Add(pluginPath); } foreach (string constant in InitialPreprocessorConstants) { hash = hash.Add(constant); } hash = hash.Add(InstallationId.ToString()); string cacheDirPath = GetCurrentUserPluginCacheDir(); string cacheFileName = hash + ".xml"; cacheFilePath = Path.Combine(cacheDirPath, cacheFileName); if (Directory.Exists(cacheDirPath)) { if (File.Exists(cacheFilePath)) { Cache oldCache = ReadCacheFile(cacheFilePath); if (oldCache != null) { foreach (var pluginInfo in oldCache.PluginInfos) { pluginCallback(pluginInfo.Plugin, new DirectoryInfo(pluginInfo.BaseDirectory), pluginInfo.PluginFile); } return; } } } else { Directory.CreateDirectory(cacheDirPath); } } catch (Exception) { // Fallback on any failure. // There can be all sorts of weird security exceptions that will prevent // us from manipulating the local application data directory. base.LoadPlugins(pluginCallback, progressMonitor); return; } // Load plugin metadata. var newCache = new Cache { InstallationId = InstallationId.ToString() }; base.LoadPlugins((plugin, baseDirectory, pluginFile) => { newCache.PluginInfos.Add(new CachePluginInfo { Plugin = plugin, BaseDirectory = baseDirectory.FullName, PluginFile = pluginFile, PluginFileModificationTime = File.GetLastWriteTimeUtc(pluginFile) }); pluginCallback(plugin, baseDirectory, pluginFile); }, progressMonitor); // Attempt to store it in the cache. try { WriteCacheFile(cacheFilePath, newCache); } catch (Exception) { // Ignore any failure. } }
/// <inheritdoc /> protected override void LoadPlugins(PluginCallback pluginCallback, IProgressMonitor progressMonitor) { // Attempt to read the old cache. string cacheFilePath; try { Hash64 hash = new Hash64(); foreach (string pluginPath in PluginPaths) hash = hash.Add(pluginPath); foreach (string constant in InitialPreprocessorConstants) hash = hash.Add(constant); hash = hash.Add(InstallationId.ToString()); string cacheDirPath = GetCurrentUserPluginCacheDir(); string cacheFileName = hash + ".xml"; cacheFilePath = Path.Combine(cacheDirPath, cacheFileName); if (Directory.Exists(cacheDirPath)) { if (File.Exists(cacheFilePath)) { Cache oldCache = ReadCacheFile(cacheFilePath); if (oldCache != null) { foreach (var pluginInfo in oldCache.PluginInfos) pluginCallback(pluginInfo.Plugin, new DirectoryInfo(pluginInfo.BaseDirectory), pluginInfo.PluginFile); return; } } } else { Directory.CreateDirectory(cacheDirPath); } } catch (Exception) { // Fallback on any failure. // There can be all sorts of weird security exceptions that will prevent // us from manipulating the local application data directory. base.LoadPlugins(pluginCallback, progressMonitor); return; } // Load plugin metadata. var newCache = new Cache { InstallationId = InstallationId.ToString() }; base.LoadPlugins((plugin, baseDirectory, pluginFile) => { newCache.PluginInfos.Add(new CachePluginInfo { Plugin = plugin, BaseDirectory = baseDirectory.FullName, PluginFile = pluginFile, PluginFileModificationTime = File.GetLastWriteTimeUtc(pluginFile) }); pluginCallback(plugin, baseDirectory, pluginFile); }, progressMonitor); // Attempt to store it in the cache. try { WriteCacheFile(cacheFilePath, newCache); } catch (Exception) { // Ignore any failure. } }