Wow! I didn't know about this. This should probably be in den
scaffolding db.py file.
One question: When does this cache expire?
BTW, I tried it like you suggested:
try:
from gluon.contrib.gql import *
except:
db=SQLDB('sqlite://storage.db')
else:
db=GQLDB()
from gluon.contrib.memdb import *
from google.appengine.api.memcache import Client
session.connect(request, response, db=MEMDB(Client()))
db.define_table('key',
SQLField('now', 'datetime'),
SQLField('line', 'text'))
which fails because importing * from gluon.contrib.memdb overwrites
SQLField already defined in gluon.contrib.gql. I changed it to
from gluon.contrib.memdb import MEMDB
and it seems to work fine.
Kind regards,
Markus
Can the session be stored in cache.ram without gluon.contrib.memcache?
Kind regards,
Markus
I already tried this using Pythons module caching:
import applications.welcome.modules.ramdb
session.connect(request, response, db=applications.welcome.modules.ramdb.db)
where applications.welcome.modules.ramdb contains
from gluon.sql import SQLDB
db = SQLDB('sqlite:memory:')
Unfortunately this gives a traceback due to SQLites thread
restriction. The exception message reads:
"ProgrammingError: SQLite objects created in a thread can only be used
in that same thread.The object was created in thread id 1332 and this
is thread id 2584"
Kind regards,
Markus
Please find attached db.py which includes the option to store sessions
in Memcache. It also fixes the damage to the comment formatting which
was done by PythonTidy.py.
This should go into the scaffolding app.
Markus
I agree it is already quite big. But until the auth stuff is
documented in the regular documentation I was not opposed to your
decision to add all those comments.
> Why include memcaching on GAE and not ram caching on non-GAE?
1. On GAE if one wants to use sessions, something has to be done
expicitely. Either store it in BigTable, or, which I just learned two
days ago, store it in Google Memcache, which is IMO a superior
solution, since it does not lead to piling up all those sessions in
BigTable. And since access to BigTable is under quota, it seems to be
another reason to have sessions stored in Memcache.
2. On non-GAE sessions work out of the box, so it is not mandatory to
tweak session handling. Memcache on non-GAE requires setting up a
Memcached server, so it would not be enough to just uncomment a few
lines in db.py. And caching the sessions in RAM is IMO currently not
possible with web2py. Am I wrong?
Kind regards,
Markus