Skip to content

Spring Data Redis Cache implementation is not compatible with Cache.retrieve(key) semantics #31637

Closed
@yangwenliang123

Description

@yangwenliang123

In the CacheAspectSupport.findInCaches method
CompletableFuture<?> cachedFuture = cache.retrieve(key);
spring cache result is null, spring redis cache result is CompletableFuture.completedFuture(null) causing result return error

@Nullable
public Object findInCaches(CacheOperationContext context, Cache cache, Object key) {
	ReactiveAdapter adapter = this.registry.getAdapter(context.getMethod().getReturnType());
	if (adapter != null) {
		CompletableFuture<?> cachedFuture = cache.retrieve(key);
		if (cachedFuture == null) {
			return null;
		}
		if (adapter.isMultiValue()) {
			return adapter.fromPublisher(Flux.from(Mono.fromFuture(cachedFuture))
					.flatMap(v -> (v instanceof Iterable<?> iv ? Flux.fromIterable(iv) : Flux.just(v))));
		}
		else {
			return adapter.fromPublisher(Mono.fromFuture(cachedFuture));
		}
	}
	return NOT_HANDLED;
}

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions