Update docs

This commit is contained in:
Vladislav Oleshko 2022-07-04 12:59:33 +03:00
parent 36e59f07ec
commit c9eda03a7a

View File

@ -18,18 +18,17 @@ Session data can be stored in multiple ways:
__Always list the CookieParser before the Session__ __Always list the CookieParser before the Session__
```cpp ```cpp
using Session = crow::SessionMiddleware<crow::InMemoryStore>; using Session = crow::SessionMiddleware<crow::FileStore>;
crow::App<crow::CookieParser, Session> app{Session{ crow::App<crow::CookieParser, Session> app{Session{
"MY_SECRET_KEY", crow::FileStore{"/tmp/sessiondata"}
crow::InMemoryStore{}
}}; }};
``` ```
Session ids are stored in cookies and are signed with a secret key. After the key changes, all cookies are invalidated. Check the example for more details about expiration management and customization. Session ids are represented as random alphanumeric strings and are stored in cookies. See the examples for more customization options.
### Usage ### Usage
A session is basically a key-value map with support for multiple types: strings, integers, booleans and doubles. A session is basically a key-value map with support for multiple types: strings, integers, booleans and doubles. The map is created and persisted automatically as soon it is first written to.
```cpp ```cpp
auto& session = app.get_context<Session>(request); auto& session = app.get_context<Session>(request);
@ -51,14 +50,6 @@ session.apply("views", [](int v){return v + 1;}); // this operation is always at
session.mutex().lock(); // manually lock session session.mutex().lock(); // manually lock session
``` ```
The session is created as soon as it is written to, but we can check whether it already exists.
We can also request a specific id for the session when it is created. This is only useful for custom stores that will support equal ids on multiple clients. Because the cookie is signed, any id is secure.
```cpp
if (!session.exists()) {
session.preset_id(user_email);
}
```
### Expiration ### Expiration
Expiration can happen either by the cookie expiring or the store deleting "old" data. Expiration can happen either by the cookie expiring or the store deleting "old" data.