Reputation: 549
I have a web application with a login system which uses a wcf service. The user type his username/password to login, then we create a unique token for the user and then the token is saved in the browser cookies to keep the user online. Everytime the user send a request, his token is sent along with the request. We keep all the tokens in a basic List
in the service memory. Now, I'm asking myself if it is the best way to do this. Will iis recycle my app memory? I have read this question about keeping a list in a wcf service and it looks like I should avoid using a list in memory. What is the best alternative to this?
Thanks
Upvotes: 1
Views: 372
Reputation: 107387
Yes, if the App Pool housing your WCF Service is recycled, you will lose everything you've cached in memory, so you will also need a persistence fallback (e.g. RDBMS or NoSql database) which will be re-loaded on resumption.
You don't say what you want stored along with the token. If its just the string token, then a HashSet<string>
might be best, and if there is other data, then a ConcurrentDictionary<string, Whatever>
would work best.
Assuming that as users login / logout of your service that the token collection will need to be mutated, which means that concurrency issues need to be considered, (you've got that with the ConcurrentDictionary
)
And you'll also need to consider the effects of stale tokens - you'll want to remove / delete unused tokens (memory and database).
Upvotes: 1