Description
I don't know if it is a BUG or Enhancement feature.
Problem:
Today i have some services that i want to support different cache rules to different routes to my service, but as it is today in sortCaches
function if i have different cache rules with groups it logs errors and return 0 cache rules to be applied.
tree-gateway/src/pipeline/cache/cache.ts
Line 110 in a1ed94e
It doesn't allow me for example to do as follows:
name: 'My Service'
...
path: /my-service/
group:
-
id: TwoMinuteCache
member:
-
method:
- GET
path:
- get-something
-
id: TenMinuteCache
member:
-
method:
- GET
path:
- get-anotherthing
-
id: GeneralGroup
member:
-
method:
- POST
- GET
- PUT
- DELETE
- OPTIONS
protocol:
- http
path:
- '!(get-something|get-anotherthing)'
proxy:
target:
host: 'http://172.18.0.1:port'
timeout: '1 minute'
cache:
-
server:
cacheTime: 10 minutes
binary: true
group:
- TenMinuteCache
-
server:
cacheTime: 2 minutes
binary: true
group:
- TwoMinuteCache
- GeneralGroup
throttling:
-
timeWindow: '1 minute'
max: 100
authentication:
strategy:
name: jwt
options:
...
group:
- GeneralGroup
- TwoMinuteCache
- TenMinuteCache
interceptor:
request:
-
middleware:
name: some-middleware
With this type of config today, it returns 0 cache rules and the gateway doesn't cache anything into redis.
As I said, i don't know if this is a intended behaviour or it is a BUG.
Solution
To support different cache rules to distinct paths we could do:
- Check if exists another cache rule with the same group an throw an error, returning 0 cache rules.
- Keep all cache rules and apply the last appearence by group and log a duplicate group cache rule warning.
I'm currently forking and posting my PR with the last option implemented, but we should discuss the best option to go from here.