public async Task <string> Get(string key) { if (key == null) { throw new ArgumentNullException(nameof(key)); } // if it contains the key, just return if (CacheExtensions.TryGetValue(_cache, key, out string cachedValue)) { return(cachedValue); } var value = await GetOrCreate(key); if (value != null) { // the memory cache is threadsafe so we don't need to acquire the lock. the worst case // scenrio is we call the underlying consul service multiple times initially, but it would // be faster than getting the lock everytime CacheExtensions.Set <string>(_cache, key, value, new MemoryCacheEntryOptions() { AbsoluteExpiration = DateTime.Now.Add(_expirationTimeSpan) }); } return(value); }
// Token: 0x0600017E RID: 382 RVA: 0x00006EDC File Offset: 0x000050DC private Task <CompiledViewDescriptor> OnCacheMiss(string normalizedPath) { object cacheLock = this._cacheLock; ViewCompilerWorkItem viewCompilerWorkItem; MemoryCacheEntryOptions memoryCacheEntryOptions; TaskCompletionSource <CompiledViewDescriptor> taskCompletionSource; lock (cacheLock) { Task <CompiledViewDescriptor> result; if (CacheExtensions.TryGetValue <Task <CompiledViewDescriptor> >(this._cache, normalizedPath, out result)) { return(result); } CompiledViewDescriptor precompiledView; if (this._precompiledViews.TryGetValue(normalizedPath, out precompiledView)) { this._logger.ViewCompilerLocatedCompiledViewForPath(normalizedPath); viewCompilerWorkItem = this.CreatePrecompiledWorkItem(normalizedPath, precompiledView); } else { viewCompilerWorkItem = this.CreateRuntimeCompilationWorkItem(normalizedPath); } memoryCacheEntryOptions = new MemoryCacheEntryOptions(); for (int i = 0; i < viewCompilerWorkItem.ExpirationTokens.Count; i++) { memoryCacheEntryOptions.ExpirationTokens.Add(viewCompilerWorkItem.ExpirationTokens[i]); } taskCompletionSource = new TaskCompletionSource <CompiledViewDescriptor>(); if (!viewCompilerWorkItem.SupportsCompilation) { taskCompletionSource.SetResult(viewCompilerWorkItem.Descriptor); } _cacheKeyList.Add(normalizedPath); CacheExtensions.Set <Task <CompiledViewDescriptor> >(this._cache, normalizedPath, taskCompletionSource.Task, memoryCacheEntryOptions); } if (viewCompilerWorkItem.SupportsCompilation) { CompiledViewDescriptor descriptor = viewCompilerWorkItem.Descriptor; if (((descriptor != null) ? descriptor.Item : null) != null && ChecksumValidator.IsItemValid(this._projectEngine.FileSystem, viewCompilerWorkItem.Descriptor.Item)) { taskCompletionSource.SetResult(viewCompilerWorkItem.Descriptor); return(taskCompletionSource.Task); } this._logger.ViewCompilerInvalidingCompiledFile(viewCompilerWorkItem.NormalizedPath); try { CompiledViewDescriptor compiledViewDescriptor = this.CompileAndEmit(normalizedPath); compiledViewDescriptor.ExpirationTokens = memoryCacheEntryOptions.ExpirationTokens; taskCompletionSource.SetResult(compiledViewDescriptor); } catch (Exception exception) { taskCompletionSource.SetException(exception); } } return(taskCompletionSource.Task); }
public void Clear(string key) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } if (CacheExtensions.TryGetValue(_cache, key, out string value)) { this._cache.Remove(key); } }
public T Get <T>(string key) { if (!CacheExtensions.TryGetValue <T>(this._cache, key, ref V_0)) { V_1 = default(T); return(V_1); } if (!this._clone) { return(V_0); } return(Utils.DeepClone <T>(V_0)); }
/// <inheritdoc /> // Token: 0x0600017D RID: 381 RVA: 0x00006E8C File Offset: 0x0000508C public Task <CompiledViewDescriptor> CompileAsync(string relativePath) { if (relativePath == null) { throw new ArgumentNullException("relativePath"); } Task <CompiledViewDescriptor> result; if (CacheExtensions.TryGetValue <Task <CompiledViewDescriptor> >(this._cache, relativePath, out result)) { return(result); } string normalizedPath = this.GetNormalizedPath(relativePath); if (CacheExtensions.TryGetValue <Task <CompiledViewDescriptor> >(this._cache, normalizedPath, out result)) { return(result); } result = this.OnCacheMiss(normalizedPath); return(result); }