Skip to content

Commit e8cad59

Browse files
committed
Merge branch 'release_4.4' into release_4.5
2 parents fa165d8 + 735615f commit e8cad59

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

docs/developers/applications/caching.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ export class MyTableEndpoint extends MyTable {
116116
117117
### Subscriptions
118118
119-
We can provide more control of an active cache with subscriptions. If there is a way to receive notifications from the external data source of data changes, we can implement this data source as an "active" data source for our cache by implementing a `subscribe` method. A `subscribe` method should return an asynchronous iterable that iterates and returns events indicating the updates. One straightforward way of creating an asynchronous iterable is by defining the `subscribe` method as an asynchronous generator. If we had an endpoint that we could poll for changes, we could implement this like:
119+
We can provide more control of an active cache with subscriptions. If there is a way to receive notifications from the external data source of data changes, we can implement this data source as an "active" data source for our cache by implementing a `subscribe` method. A `subscribe` method should return an asynchronous iterable that iterates and returns events indicating the updates. One straightforward way of creating an asynchronous iterable is by defining the `subscribe` method as an asynchronous generator. If we had an endpoint that we could poll for changes every second, we could implement this like:
120120
121121
```javascript
122122
class ThirdPartyAPI extends Resource {
123123
async *subscribe() {
124-
do {
124+
setInterval(() => { // every second retrieve more data
125125
// get the next data change event from the source
126126
let update = (await fetch(`http://some-api.com/latest-update`)).json();
127127
const event = { // define the change event (which will update the cache)
@@ -131,7 +131,7 @@ class ThirdPartyAPI extends Resource {
131131
timestamp: // the timestamp of when the data change occurred
132132
};
133133
yield event; // this returns this event, notifying the cache of the change
134-
} while(true);
134+
}, 1000);
135135
}
136136
async get() {
137137
...

docs/technical-details/reference/globals.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class Origin {
113113
}
114114
Cache.sourcedFrom(Origin);
115115
```
116+
- `login(username, password): Promise<void>` - This method can be called to start an authenticated session. The login will authenticate the user by username and password. If the authentication was successful, a session will be created and a cookie will be set on the response header that references the session. All subsequent requests from the client that sends the cookie in requests will be authenticated as the user that logged in and the session record will be attached to the request. This method returns a promise that resolves when the login is successful, and rejects if the login is unsuccessful.
117+
- `session` - This is the session object that is associated with current cookie-maintained session. This object is used to store session data for the current session. This is `Table` record instance, and can be updated by calling `request.session.update({ key: value })` or session can be retrieved with `request.session.get()`. If the cookie has not been set yet, a cookie will be set the first time a session is updated or a login occurs.
116118
- `_nodeRequest` - This is the underlying Node.js [`http.IncomingMessage`](https://nodejs.org/api/http.html#http_class_http_incomingmessage) object. This can be used to access the raw request data, such as the raw headers, raw body, etc. However, this is discouraged and should be used with caution since it will likely break any other server handlers that depends on the layered `Request` call with `Response` return pattern.
117119
- `_nodeResponse` - This is the underlying Node.js [`http.ServerResponse`](https://nodejs.org/api/http.html#http_class_http_serverresponse) object. This can be used to access the raw response data, such as the raw headers. Again, this is discouraged and can cause problems for middleware, should only be used if you are certain that other server handlers will not attempt to return a different `Response` object.
118120

0 commit comments

Comments
 (0)