spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Field routesToCache inner class AdaptCachedBodyGlobalFilter maybe should be modified

Open Penough opened this issue 1 year ago • 1 comments

Describe. I noticed that it's a good way to use AdaptCachedBodyGlobalFilter to cache request body in the scenario of reuse.And I see it listening a EnableBodyCachingEvent event to judge whether or not to cache the request body.As a result, the field routesToCache will only have the entries with true value.I also notice the RetryGatewayFilterFactory use the event.Once I configure the routes with retry filter, the route will have the feature with caching request body permanently.I can't stop the behavior by revise the configuration in configuration center which support hot loading by refreshing routes.

	private ConcurrentMap<String, Boolean> routesToCache = new ConcurrentHashMap<>();
	@Override
	public void onApplicationEvent(EnableBodyCachingEvent event) {
		this.routesToCache.putIfAbsent(event.getRouteId(), true);
	}

Describe the solution you'd like I think AdaptCachedBodyGlobalFilter should support one more event such as DisableBodyCachingEvent to set/delete the entry in routesToCache.

Penough avatar May 24 '24 07:05 Penough

+1 for DisableBodyCachingEvent. In our scenario, routes can have a metadata flag that enables or disables caching for that specific route. So if the route is added via the actuator API with enabled: true and then updated with enabled: false there is no way to update routesToCache.

dpozinen avatar Sep 19 '24 09:09 dpozinen