Skip to content

Discussion: Handle Session Expiry #8

Closed
@No9

Description

@No9

Hey Folks
As mentioned in the code https://github.com/yoshuawuyts/async-mongodb-session/blob/master/src/lib.rs#L49
Sessions do not expire at the moment.

Looking at the mongo docs it seems expiry can be enforced using an index
https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-after-a-specified-number-of-seconds

It should be simple enough to code (famous last words when talking about cache expiry :) ), but wanted to clarify a some points before i started.

The approach I am considering is to add an additional parameter called expireAfterSeconds to connect and from_client
Is that ok?

Currently the session object in async-session only has an expiry field https://github.com/http-rs/async-session/blob/main/src/session.rs#L59 .
Using the inbuilt TTL in mongo means that the property in this scenario is not an expiry time but the creation time that will be offset with the expireAfterSeconds value to calculate the expiry time.
I can proceed using the expiry field but would suggest that we change the name of the of the session object to expiry-marker.
If that makes sense I can PR that as part of this.

As the TTL is an index it will have to be redefined on restart in the case where the user changes the value following restarts.
This will be done using collMod https://docs.mongodb.com/manual/reference/command/collMod/#dbcmd.collMod

It would be great if we can finalise #7 as expiry will will need tests and I wouldn't want to do too much using an approach that hasn't landed.

Thanks for your time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions