コード例 #1
0
ファイル: FileCacheLayerBase.cs プロジェクト: vp89/CacheTower
		private async Task TryLoadManifestAsync()
		{
			//Avoid unnecessary lock contention way after manifest is loaded by checking before lock
			if (CacheManifest is null)
			{
				await ManifestLock.WaitAsync();
				try
				{
					//Check that once we have lock (due to a race condition on the outer check) that we still need to load the manifest
					if (CacheManifest is null)
					{
						if (File.Exists(ManifestPath))
						{
							CacheManifest = await DeserializeFileAsync<ConcurrentDictionary<string?, IManifestEntry>>(ManifestPath);
						}
						else
						{
							if (!Directory.Exists(DirectoryPath))
							{
								Directory.CreateDirectory(DirectoryPath);
							}

							CacheManifest = new ConcurrentDictionary<string?, IManifestEntry>();
							await SerializeFileAsync(ManifestPath, CacheManifest);
						}
					}
				}
				finally
				{
					ManifestLock.Release();
				}
			}
		}
コード例 #2
0
ファイル: FileCacheLayerBase.cs プロジェクト: vp89/CacheTower
		/// <summary>
		/// Saves the cache manifest to the file system.
		/// </summary>
		/// <returns></returns>
		public async Task SaveManifestAsync()
		{
			await ManifestLock.WaitAsync();
			try
			{
				if (!Directory.Exists(DirectoryPath))
				{
					Directory.CreateDirectory(DirectoryPath);
				}

				await SerializeFileAsync(ManifestPath, CacheManifest);
			}
			finally
			{
				ManifestLock.Release();
			}
		}