예제 #1
0
 private async ValueTask <IDictionary <string, ActivityType> > GetDictionaryAsync(CancellationToken cancellationToken)
 {
     return(await _memoryCache.GetOrCreate(CacheKey, async entry =>
     {
         entry.Monitor(_cacheSignal.GetToken(CacheKey));
         return await GetActivityTypesInternalAsync(cancellationToken).ToDictionaryAsync(x => x.TypeName, cancellationToken);
     }));
 }
 private async Task <ICollection <IWorkflowBlueprint> > ListInternalAsync(CancellationToken cancellationToken)
 {
     return(await _memoryCache.GetOrCreateAsync(CacheKey, async entry =>
     {
         entry.Monitor(_cacheSignal.GetToken(CacheKey));
         return await _workflowRegistry.ListAsync(cancellationToken).ToList();
     }));
 }
예제 #3
0
        public override ValueTask SaveAsync(WorkflowStorageContext context, string key, object?value, CancellationToken cancellationToken = default)
        {
            var workflowInstanceId = context.WorkflowInstance.Id;
            var activityId         = context.ActivityId;
            var cacheKey           = GetKey(workflowInstanceId, activityId, key);
            var options            = new MemoryCacheEntryOptions();

            options.ExpirationTokens.Add(_cacheSignal.GetToken(GetSignalKey(workflowInstanceId)));
            _cache.Set(cacheKey, value, options);

            return(new ValueTask());
        }
예제 #4
0
        public async Task <IWorkflowBlueprint?> FindInternalAsync(string cacheKey, Func <Task <IWorkflowBlueprint?> > findAction, CancellationToken cancellationToken = default)
        {
            return(await _memoryCache.GetOrCreateAsync(cacheKey, async entry =>
            {
                var workflowBlueprint = await findAction();

                if (workflowBlueprint != null)
                {
                    var key = GetEvictionKey(workflowBlueprint.Id);
                    entry.Monitor(_cacheSignal.GetToken(key));
                }

                return workflowBlueprint;
            }));
        }
예제 #5
0
 public IChangeToken GetToken(string key) => _cacheSignal.GetToken(key);