Reputation: 2970
I am actually building a chat application which has to show current users, I have a column 'IsOnline' in db whose value toggles between 1 and 0 as user logs in or out. I need a function which hits api every 15 seconds to get latest users who are currently online. Since I am using entity framework which does not support signalr and sql dependency I have decided to go this way. How can I have a method which runs every 15 seconds in a separate thread so as not to interfere my other crud operations as long I have user in session.
Upvotes: 0
Views: 108
Reputation: 553
Store status in memory, for instance in memcached or redis. Have the client issue a request every 15 seconds. The online status is transient, it does not need to be stored in DB.
It's hard to advise in depth because you did not describe the architecture of your app.
In general, efficient implmentation of presence notifications is tricky. It may be easier to take something off the shelf instead of developing your own.
Upvotes: 1
Reputation: 496
Polling after 15 second is not a good solution especially if your call is on DB. Think about the latency in this approach. I think you need to look for different approach rather than calling db after 15 second.
If you want to check online/offline maintain the status in memory rather than Persist in Db (persist after 1 hour or 2 hour if you want to keep in DB).
Upvotes: 1