Ivan Fioravanti - 39 - Nov 5, 2014

Hi Demis,
is there a way in ServiceStack to  slide session expiration? I’ve seen the solution suggested here: http://stackoverflow.com/questions/14857921/how-to-advance-the-session-timeout-in-servicestack but I was wondering if there is something built-in in the recent releases.

Everytime you save the Session it automatically saves it with the ExpiryTime set in the first AuthProvider.SessionExpiry or
 SessionFeature.DefaultSessionExpiry.

Dan wrote about another solution using a ResponseFilter Attribute instead: http://teadriven.me.uk/2013/02/14/sliding-sessions-in-service-stack/

This is not something SS could optimize, i.e. any solution in ServiceStack would need to do the same thing under the hood, and if SS did it implicitly, it’d be hard to know when or control how many times SS touches the session for this.

BTW what ICacheClient provider are you using?

Ivan Fioravanti:

Redis, so I’ll follow your suggestion of manually updating the expiry timeout without re-reading the entry.

yep IMO that’s the best approach. Note you can get the session cache key with:

var sessionKey = SessionFeature.GetSessionKey(httpReq.GetSessionId());