public async Task <(bool success, Stream result)> TryOpenReadAsync(IDocument entry, CancellationToken ct) { string name = entry.FullPath(); var v = await Store.TryGet(name); if (!RequestLockManager.GetStatus(name).Is(RequestStatus.IgnoreCache)) { await Predictor.Request(name); } return(v); }
public async Task TryOpenReadAsync_Bubbleup(IDocument entry, Stream result, CancellationToken ct) { string name = entry.FullPath(); if (!RequestLockManager.GetStatus(name).Is(RequestStatus.IgnoreCache)) { int key = rand.Next(); activePredicitveFillKey = key; await Predictor.Request_Bubbleup(name); ThreadPool.QueueUserWorkItem(async(x) => await PredicitiveFillCache(key, ct)); } }
public async Task TryOpenReadAsync_Bubbleup(IDocument entry, Stream result, CancellationToken ct) { string name = entry.FullPath(); if (!IgnoreIgnoreCache && RequestLockManager.GetStatus(name).Is(RequestStatus.IgnoreCache)) { return; } if (result.CanSeek) { if (result is IDelayedDisposable) { (result as IDelayedDisposable).OnDisposeAsync.Add(async() => { result.Position = 0; await Store.TryPut(name, result); }); } else { await Store.TryPut(name, result); result.Position = 0; } RequestLockManager.AddStatus(name, RequestStatus.Cached); } else if (result is PushReadStream && !RequestLockManager.GetStatus(name).Is(RequestStatus.IgnoreCache) && await Allocator.TryAllocate(name, () => Task.FromResult(entry), () => Task.FromResult(result)) ) { PushReadStream prs = result as PushReadStream; prs.AddListener(new DocumentCacheStreamListener(prs, this, name)); RequestLockManager.AddStatus(name, RequestStatus.Cached); } }