Skip to content

Commit 51836bb

Browse files
authored
lib: more cache fixes (#3816)
1 parent 2b81fbc commit 51836bb

File tree

12 files changed

+512
-488
lines changed

12 files changed

+512
-488
lines changed

docs/docs/api/CacheStore.md

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
A Cache Store is responsible for storing and retrieving cached responses.
44
It is also responsible for deciding which specific response to use based off of
5-
a response's `Vary` header (if present).
5+
a response's `Vary` header (if present). It is expected to be compliant with
6+
[RFC-9111](https://www.rfc-editor.org/rfc/rfc9111.html).
67

78
## Pre-built Cache Stores
89

@@ -21,27 +22,33 @@ The store must implement the following functions:
2122

2223
### Getter: `isFull`
2324

24-
This tells the cache interceptor if the store is full or not. If this is true,
25+
Optional. This tells the cache interceptor if the store is full or not. If this is true,
2526
the cache interceptor will not attempt to cache the response.
2627

27-
### Function: `createReadStream`
28+
### Function: `get`
2829

2930
Parameters:
3031

3132
* **req** `Dispatcher.RequestOptions` - Incoming request
3233

33-
Returns: `CacheStoreReadable | Promise<CacheStoreReadable | undefined> | undefined` - If the request is cached, a readable for the body is returned. Otherwise, `undefined` is returned.
34+
Returns: `GetResult | Promise<GetResult | undefined> | undefined` - If the request is cached, the cached response is returned. If the request's method is anything other than HEAD, the response is also returned.
35+
If the request isn't cached, `undefined` is returned.
36+
37+
Response properties:
38+
39+
* **response** `CachedResponse` - The cached response data.
40+
* **body** `Readable | undefined` - The response's body.
3441

3542
### Function: `createWriteStream`
3643

3744
Parameters:
3845

3946
* **req** `Dispatcher.RequestOptions` - Incoming request
40-
* **value** `CacheStoreValue` - Response to store
47+
* **value** `CachedResponse` - Response to store
4148

42-
Returns: `CacheStoreWriteable | undefined` - If the store is full, return `undefined`. Otherwise, return a writable so that the cache interceptor can stream the body and trailers to the store.
49+
Returns: `Writable | undefined` - If the store is full, return `undefined`. Otherwise, return a writable so that the cache interceptor can stream the body and trailers to the store.
4350

44-
## `CacheStoreValue`
51+
## `CachedResponse`
4552

4653
This is an interface containing the majority of a response's data (minus the body).
4754

@@ -55,15 +62,11 @@ This is an interface containing the majority of a response's data (minus the bod
5562

5663
### Property `rawHeaders`
5764

58-
`(Buffer | Buffer[])[]` - The response's headers.
59-
60-
### Property `rawTrailers`
61-
62-
`string[] | undefined` - The response's trailers.
65+
`Buffer[]` - The response's headers.
6366

6467
### Property `vary`
6568

66-
`Record<string, string> | undefined` - The headers defined by the response's `Vary` header
69+
`Record<string, string | string[]> | undefined` - The headers defined by the response's `Vary` header
6770
and their respective values for later comparison
6871

6972
For example, for a response like
@@ -95,22 +98,3 @@ This would be
9598
is either the same sa staleAt or the `max-stale` caching directive.
9699

97100
The store must not return a response after the time defined in this property.
98-
99-
## `CacheStoreReadable`
100-
101-
This extends Node's [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable)
102-
and defines extra properties relevant to the cache interceptor.
103-
104-
### Getter: `value`
105-
106-
The response's [`CacheStoreValue`](#cachestorevalue)
107-
108-
## `CacheStoreWriteable`
109-
110-
This extends Node's [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable)
111-
and defines extra properties relevant to the cache interceptor.
112-
113-
### Setter: `rawTrailers`
114-
115-
If the response has trailers, the cache interceptor will pass them to the cache
116-
interceptor through this method.

0 commit comments

Comments
 (0)