BORHANUDDIN1 / webapp-improved

Automatically exported from code.google.com/p/webapp-improved
Other
0 stars 0 forks source link

How to remove all sessions? #27

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I have no idea how to do it.

Original issue reported on code.google.com by nabokov.evgeni on 10 Nov 2011 at 10:38

GoogleCodeExporter commented 9 years ago
I use datastore for storing sessions. Of couse I can use Datastore viewer to 
clear Session king, but I want to do it in my Python code.

Original comment by nabokov.evgeni on 10 Nov 2011 at 10:40

GoogleCodeExporter commented 9 years ago
My solution. I created a fake kind "Session":

class Session(db.Model):
    pass

Then call delete():

for s in Session.gql("").fetch(1000):
    s.delete()

Original comment by nabokov.evgeni on 10 Nov 2011 at 11:14

GoogleCodeExporter commented 9 years ago
And then:

memcache.flush_all()

Original comment by nabokov.evgeni on 10 Nov 2011 at 11:15

GoogleCodeExporter commented 9 years ago
You could also use the ndb model:

from webapp2_extras.appengine.sessions_ndb import Session

for s in Session.query().fetch():
    s.delete()

I think a more comprehensive solution would also allow for the removing of 
expired / invalid sessions. Something that could be called from a cron job.

Original comment by kylefin...@gmail.com on 17 Nov 2011 at 10:16

GoogleCodeExporter commented 9 years ago
I would like to have a handler for this, to be scheduled via cron and taking 
into account that one can have many sessions to be cleaned, so a single request 
may not be sufficient.

I described it here, and I'm looking for contributions:
https://plus.google.com/u/0/b/110207997506115788259/110207997506115788259/posts/
EvTyDUqi85J

Original comment by rodrigo.moraes on 18 Nov 2011 at 11:23