Hello!I have found that we set data to memcache on unlimited time:# line 314memcache.set(self.sid, pdump, namespace='') # may fail if memcache is down
We need set this session data to limited time, specified in constructor (for example, on 7 days). After this, we have cleaned old sessions automatically and, if user open page - then data fetched from database and copied to memcache on next 7 days. This is useful improvement for save memcache resources.Solution is:memcache.set(self.sid, pdump, namespace='', time=CURRENT_DATETIME + 7DAYS)
And also, I propose add column to SessionModel with automatically updated datetime property. This help us select all expired sessions and delete his. For example, we can do something like this in delete_expired_sessions() method:SessionModel.filter("date <", CURRENT_DATETIME - 7DAYS).limit(1000).delete()
I propose to do automatically setting up of Cookie key. See how I does it in this code http://code.google.com/p/appengine-framework/source/browse/trunk/src/appengine_config.py?r=311#4QUESTION: if I have set Model object to session, what kind of information to be stored? For example, I have next code:# usaerl logged in by emailuser = models.User.get(email="te...@example.com")# store user object to sessionsession["user"] = userIn this case, what to be stored in memcache and datastore? Only Model ID for wake-up of object on the next request OR object as it is?
I need always get fresh information about user (username, email, etc). If I have store object as it is - this is not a good.
I need store only Model ID and wakeup Model on each user request to site.
About datetime column. I see on this situation with the next vision:1) I have logged in to site, and my session expires, for example, after 1 hour2) after 5 minutes I have refresh website page. Now my session should be automatically updated to next hour (expired after one hour, not 55 minutes!)
As I think, now we have set session only on the one hour.
And if I have open site in this hour - my session not updated (because KEYs have not updated in the datastore - we can only delete old record and create new record with the new KEY). If this is true - please, use datetime column for SessionModel. This is a bit more data stored in the database, but this add for us more flexibility - we can easily delete expired sessions. In result - we have more saved server resources. And also - disk space for the datastore is very low-cost, As I discussed with Gooogle App Engine main developer - we need to use more disc space and save processor time - this is save our money and allow us to use more requests per second.
If user have changed some information in profile - I have see old information about user? Or, I have see changed information?# in my application by url /user/change_avataruser = self.session["user"]user.avatar = "other_avatar_image.png"user.put()In session this information automatically updated?
I propose next improvements.1) if I have set empty value to session - please delete this value from session.session['user'] = Nonesession['user2'] = "" # also delete
session['user3'] = EmptyModel() # also deletewe need to store not empty information in sessions. Why? - I have descibe this below.
2) return not copy, but same object from sessionuser = session["user"]user.avatar = "new_avatar"# we get changed data from session, because this is one object (two links to one memory place)# we have reload page and session have save changed information about user avatar# we need detect changed object in session, and renew this object in memcache and in datatoreprint session["user"] # show changed avatar
# delete user - this user automatically was delete from session because session have not save empty objects (I say about this above)user.delete()