Closed longsleep closed 3 months ago
Discussion from https://github.com/maxcountryman/tower-sessions/issues/206#issuecomment-2266214599 continues here.
While #178 might be a little bit related, but the issue this PR fixes is entirely unrelated to calling "set_expiry" or really any other optional API one could call. This here is about changing the internal behavior and I think it is simply missing this and the discussion if this behavior should be changed or not should have its dedicated place.
So, to make my point clear - here is the change which does the trick without doing any harm as no behavior changes if the expiry is actually set manually.
With this change, the loaded Session expiry would be the timestamp which was set the last time the Session was saved.
As I've mentioned already, it's not possible to hydrate Expiry
this way: the data is simply not stored in the session store as it stands.
Could you please use the existing discussion thread and issue I linked to engage with the conversation around this API?
As I've mentioned already, it's not possible to hydrate
Expiry
this way: the data is simply not stored in the session store as it stands.
What makes you say that? I assumed that session store implementations use serde to serialize and deserialze the Record
.
This is what the redis-store does: https://github.com/maxcountryman/tower-sessions-stores/blob/cecfba06e7ebc031d59d51a5926e19b3bc2c2d0d/redis-store/src/lib.rs#L77 and this change works perfectly fine with it since the expiry_date field will be serialized/deserialized.
I guess a store implementation could opt to just serialize the Record.Data
field but how would that then produce the Record when loading, after all the store API https://github.com/maxcountryman/tower-sessions-stores/blob/cecfba06e7ebc031d59d51a5926e19b3bc2c2d0d/redis-store/src/lib.rs#L110 requires a Record to be returned - what expiry_date is in there if it was not stored?
Could you please use the existing discussion thread and issue I linked to engage with the conversation around this API?
Sessions are stored together with their expiration date in the store. Whenever loading sessions from the store, the
Session
type should reflect the backend data exactly. With this change, the stored expiration date is set to theSession
type expiry data if it has not been set at initialization or by callingset_expiry
.This might introduce a behavior change for code using the
Session
type without setting an expiry. Before this change, the expiry would be relative to the current time implicitly even for existing sessions after load. With this change, the loadedSession
expiry would be the timestamp which was set the last time theSession
was saved.Fixes: https://github.com/maxcountryman/tower-sessions/issues/206