Update other user's session

I want to update sessions of a user other than the logged in user.

My use case is very similar to the one in this stackoverflow question:

The only answer there is very hacky and will only work if the cache is being stored in redis.

Is there any other way of doing this?

From what I can see, the session id is randomly generated and the session stored in the cache. So it seems that there is no way to link a UserAuthId to a session in the cache.

Right the session is random which is very important for security that sessionIds can’t be predicted.

The new high-level API’s added to ICacheClientExtended provides a common API for querying sessions in cache which is shared by most caching providers.

An alternative solution is to maintain your own mapping between User Ids and their User Session Keys by registering a custom Session Event to track sessions for each user.

Thanks, the ICacheClientExtended additions are what I was looking for.

I’ll start with the the example from the docs:

var sessionPattern = IdUtils.CreateUrn<IAuthSession>(""); //= urn:iauthsession:
var sessionKeys = Cache.GetKeysStartingWith(sessionPattern).ToList();

var allSessions = Cache.GetAll<IAuthSession>(sessionKeys);

If I have to support a lot of sessions and performance becomes an issue, I’ll have to implement your second suggestion.