/// <inheritdoc />
        public async Task <Result <LevelSelectors> > GetLevelSelectorsAsync(Context context, Fingerprint weakFingerprint, CancellationToken cts, int level)
        {
            if (_innerCacheSession is IReadOnlyMemoizationSessionWithLevelSelectors withLevelSelectors)
            {
                var result = await MetadataCache.GetOrAddSelectorsAsync(
                    context,
                    weakFingerprint,
                    fingerprint =>
                    withLevelSelectors.GetAllSelectorsAsync(context, weakFingerprint, cts));

                return(LevelSelectors.Single(result));
            }

            throw new NotSupportedException($"Inner store {_innerCacheSession.GetType().Name} does not support GetLevelSelectors functionality.");
        }
Пример #2
0
        /// <inheritdoc />
        public async Task <Result <LevelSelectors> > GetLevelSelectorsAsync(OperationContext context, Fingerprint weakFingerprint, int level)
        {
            var weakFingerprintKey = GetKey(weakFingerprint);

            var(primaryResult, secondaryResult) = await _redis.ExecuteRaidedAsync <IEnumerable <Selector> >(context, async (redis, cancellationToken) =>
            {
                using var nestedContext = new CancellableOperationContext(context, cancellationToken);
                var keys = await redis.GetHashKeysAsync(nestedContext, weakFingerprintKey, nestedContext.Context.Token);

                return(keys.Select(r => DeserializeSelector(r)).Where(t => !t.isReplacementToken).Select(t => t.selector).ToList());
            }, retryWindow : null);

            Contract.Assert(primaryResult != null || secondaryResult != null);

            var result = (primaryResult?.GetValueOrDefault() ?? EmptySelectors).Concat(secondaryResult?.GetValueOrDefault() ?? EmptySelectors).Distinct();

            return(LevelSelectors.Single <List <Selector> >(result.ToList()));
        }
 /// <inheritdoc />
 public Task <Result <LevelSelectors> > GetLevelSelectorsAsync(Context context, Fingerprint weakFingerprint, CancellationToken cts, int level)
 {
     return(Task.FromResult(LevelSelectors.Single(MemoizationStore.GetSelectorsCore(context, weakFingerprint, cts))));
 }
        /// <inheritdoc />
        public async Task <Result <LevelSelectors> > GetLevelSelectorsAsync(Context context, Fingerprint weakFingerprint, CancellationToken cts, int level)
        {
            var result = await GetSelectorsAsync(context, weakFingerprint);

            return(LevelSelectors.Single(result));
        }
 /// <inheritdoc />
 protected override Task <Result <LevelSelectors> > GetLevelSelectorsCoreAsync(OperationContext context, Fingerprint weakFingerprint, int level)
 {
     return(Task.FromResult(LevelSelectors.Single(Database.GetSelectors(context, weakFingerprint))));
 }
Пример #6
0
 /// <inheritdoc />
 public async Task <Result <LevelSelectors> > GetLevelSelectorsAsync(Context context, Fingerprint weakFingerprint, CancellationToken cts, int level)
 {
     return(LevelSelectors.Single(await MemoizationStore.GetSelectorsCoreAsync(context, weakFingerprint)));
 }