コード例 #1
0
ファイル: DocumentPredictor.cs プロジェクト: Pater1/Hotplay
        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);
        }
コード例 #2
0
ファイル: DocumentPredictor.cs プロジェクト: Pater1/Hotplay
        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));
            }
        }
コード例 #3
0
ファイル: DocumentCache.cs プロジェクト: Pater1/Hotplay
        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);
            }
        }