You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cache entries will be created for all remote responses coming with the `x-cache-timeout` header:
164
-
```js
165
-
res.setHeader('x-cache-timeout', '1 hour')
166
-
```
167
-
> Here we use the [`ms`](`https://www.npmjs.com/package/ms`) package to convert timeout to seconds. Please note that `millisecond` unit is not supported!
168
-
169
-
Example on remote service using `restana`:
170
-
```js
171
-
service.get('/numbers', (req, res) => {
172
-
res.setHeader('x-cache-timeout', '1 hour')
173
-
174
-
res.send([
175
-
1, 2, 3
176
-
])
177
-
})
178
-
```
179
-
180
-
### Invalidating cache
181
-
> Let's face it, gateway level cache invalidation was complex..., until now!
Remote services can also expire cache entries on demand, i.e: when the data state changes. Here we use the `x-cache-expire` header to indicate the gateway cache entries to expire using a matching pattern:
184
-
```js
185
-
res.setHeader('x-cache-expire', '*/numbers')
186
-
```
187
-
> Here we use the [`matcher`](`https://www.npmjs.com/package/matcher`) package for matching patterns evaluation.
188
-
189
-
Example on remote service using `restana`:
190
-
```js
191
-
service.patch('/numbers', (req, res) => {
192
-
res.setHeader('x-cache-expire', '*/numbers')
193
-
194
-
// ...
195
-
res.send(200)
196
-
})
197
-
```
198
166
199
167
### Custom cache keys
200
168
Cache keys are generated using: `req.method + req.url`, however, for indexing/segmenting requirements it makes sense to allow cache keys extensions.
0 commit comments