private bool CanHandlePushRequest(Context cacheContext, ContentHash hash, [NotNullWhen(true)] IPushFileHandler store) { if (store == null) { Tracer.Debug(cacheContext, $"{nameof(HandlePushFileAsync)}: Copy of {hash.ToShortString()} skipped because no stores implement {nameof(IPushFileHandler)}."); return(false); } if (!store.CanAcceptContent(cacheContext, hash, out var rejectionReason)) { Tracer.Debug(cacheContext, $"{nameof(HandlePushFileAsync)}: Copy of {hash.ToShortString()} skipped: {rejectionReason}"); return(false); } lock (_pushesLock) { if (_ongoingPushes.Count >= _ongoingPushCountLimit) { Tracer.Debug(cacheContext, $"{nameof(HandlePushFileAsync)}: Copy of {hash.ToShortString()} skipped because the max number of proactive pushes of '{_ongoingPushCountLimit}' is reached. OngoingPushes.Count={_ongoingPushes.Count}."); return(false); } if (!_ongoingPushes.Add(hash)) { Tracer.Debug(cacheContext, $"{nameof(HandlePushFileAsync)}: Copy of {hash.ToShortString()} skipped because another request to push it is already being handled."); return(false); } } return(true); }
/// <nodoc /> public ContentCacheService( ContentCacheConfiguration configuration, IPushFileHandler pushFileHandler, IDistributedStreamStore streamStore, IDeploymentServiceClient client = null) { Configuration = configuration; StreamStore = streamStore; PushFileHandler = pushFileHandler; ContentCacheRequests = new VolatileMap <string, AsyncLazy <BoolResult> >(Clock); Client = client ?? DeploymentLauncherHost.Instance.CreateServiceClient(); DownloadQueue = new ActionQueue(configuration.DownloadConcurrency ?? Environment.ProcessorCount); }