Reputation: 989
I'm using ServiceStack's session feature (that's using memory caching), and I try to access a key in the session object, modify it and then save the session:
var filesList = Session.Get<List<string>>("NewRequestUploadedFiles");
filesList.Add(fileName);
Session["NewRequestUploadedFiles"] = filesList;
This code can be called parallely through multiple concurrent requests from the client, so locking on this key is required. Is there any built-in way to achieve locking on ISession?
For now I use memory caching, but in the future I would like to change the caching provider to Redis, so if there is any generic way, it is preferred.
Thanks in advance.
Upvotes: 1
Views: 964
Reputation: 143319
You should consider using ServiceStack's typed sessions since writes are atomic.
Otherwise if you want, you can maintain distributed locks with Redis. If it's only a single host in memory you can just use C# standard locking semantics.
Upvotes: 1