Example #1
0
 public async Task Refresh(string key, Func <Task <IDocument> > doc, Func <Task <Stream> > stream)
 {
     if (!AllocatedFiles.Contains(key))
     {
         AllocatedFiles.Add(key);
         await CacheInvalidator.Allocated(key, doc, stream);
     }
     else
     {
         await CacheInvalidator.Refresh(key, doc, stream);
     }
 }
Example #2
0
        public async Task <bool> TryAllocate(string key, Func <Task <IDocument> > doc, Func <Task <Stream> > stream)
        {
            if (AllocatedFiles.Count >= MaxAllocatedFiles && CacheInvalidator != null)
            {
                int filesToDeallocate = 1 + (AllocatedFiles.Count - MaxAllocatedFiles);
                IEnumerable <Task> deallocateAwait = CacheInvalidator.DeallocatePriorityFiles.Result
                                                     .Take(filesToDeallocate)
                                                     .SelectMany(x => OnDeallocate.Select(y => y(x)));
                await Task.WhenAll(deallocateAwait);
            }


            if (!AllocatedFiles.Contains(key))
            {
                AllocatedFiles.Add(key);
                await CacheInvalidator.Allocated(key, doc, stream);

                return(true);
            }
            else
            {
                return(false);
            }
        }