Skip to content

Commit 71bac63

Browse files
committed
updating docs related to caching
1 parent d8c30d2 commit 71bac63

File tree

1 file changed

+5
-37
lines changed

1 file changed

+5
-37
lines changed

README.md

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Caching support is provided by the `http-cache-middleware` module. https://www.n
114114
Enabling proper caching strategies at gateway level will drastically reduce the latency of your system,
115115
as it reduces network round-trips and remote services processing.
116116
We are talking here about improvements in response times from `X ms` to `~2ms`, as an example.
117+
> We use the `http-cache-middleware` module to support gateway level caching. Read more about it: https://github.com/jkyberneees/http-cache-middleware
117118
118119
### Setting up gateway level cache available for all services
119120
#### Single node cache (memory):
@@ -156,45 +157,12 @@ const server = gateway({
156157
```
157158
> Required if there are more than one gateway instances
158159
159-
### Enabling cache for service endpoints
160-
Although API Gateway level cache aims as a centralized cache for all services behind the wall, are the services
161-
the ones who indicate the responses to be cached and for how long.
160+
### How to cache endpoints response?
161+
https://github.com/jkyberneees/http-cache-middleware#enabling-cache-for-service-endpoints
162162

163-
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!
163+
### How to invalidate caches?
164+
https://github.com/jkyberneees/http-cache-middleware#invalidating-caches
182165

183-
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-
```
198166

199167
### Custom cache keys
200168
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

Comments
 (0)