开发者

cleaning up expired sessions with a custom SessionStateStoreProvider

开发者 https://www.devze.com 2022-12-23 19:28 出处:网络
开发者_高级运维I\'m implementing my own SessionStateStoreProvider with a schemaless database. It\'s a little hard to tell from the documentation but it seems as though I will have to have a separate p
开发者_高级运维

I'm implementing my own SessionStateStoreProvider with a schemaless database. It's a little hard to tell from the documentation but it seems as though I will have to have a separate process for cleaning up expired sessions since the database will not have a way to notify the session state store that a session has expired.

Am I wrong about this? I haven't seen an alternative example for overriding the SetItemExpireCallback method.


Yes I believe that is correct.

If you store the sessions on database, then there is a Job on Sql Server Agent thats call this procedure every minute or so:

    DECLARE @now datetime
    SET @now = GETUTCDATE()

    DELETE ASPStateTempSessions WHERE Expires < @now

There is no trigger for session expired. Lets say that was a trigger, where that can be ? There is no place to put that trigger alone to understand that the session expired and auto-delete his self.

From the other hand what you can do, is not to create a timer, but when a user ask for a page, every 1-2 minute, trigger a function to delete the expired ones.

So you make a trigger from a user call, but you must make it run only onces every 1-2 minutes using some kind of lock, and check for the last run.

Hope thats helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消