Using the  'django.contrib.sessions.backends.cached_db' and setting
SESSION_COOKIE_AGE to any number of seconds greater than 2592000 (i.e.
> 30 days) with memcached appears not to work as intended in that the
session info is never sent back from the cache.

Examples to illustrate:

Memcached output with SESSION_COOKIE_AGE <= 30 days (here 14 days):
<pre>
<288 new client connection
<288 get 4c35074ef4038b16a2db4f728324206a
>288 END
<288 set 4c35074ef4038b16a2db4f728324206a 1 1209600 332
>288 STORED
<288 connection closed.
<288 new client connection
<288 get 4c35074ef4038b16a2db4f728324206a
>288 sending key 4c35074ef4038b16a2db4f728324206a
>288 END
<288 connection closed.
<288 new client connection
<288 get 4c35074ef4038b16a2db4f728324206a
>288 sending key 4c35074ef4038b16a2db4f728324206a
>288 END
</pre>

Works.  After the initial store, the key is requested and sent as
expected.

Now, memcached output with SESSION_COOKIE_AGE > 30 days (here 31
days):
<pre>
<288 new client connection
<288 get 4c35074ef4038b16a2db4f728324206a
>288 END
<288 set 4c35074ef4038b16a2db4f728324206a 1 2678400 334
>288 STORED
<288 connection closed.
<288 new client connection
<288 get 4c35074ef4038b16a2db4f728324206a
>288 END
<288 set 4c35074ef4038b16a2db4f728324206a 1 2678400 334
>288 STORED
<288 connection closed.
</pre>

The key is initially stored, and each time it is requested, it doesn't
send the data but rather gets it from the db and keeps re-setting the
same key each time.

Memcached takes a seconds argument as expiry up to 30 days out.
Otherwise it appears to want a Unix timestamp to set the expiry date.
Looking at cached_db.py it passes the SESSION_COOKIE_AGE which is
always a number of seconds.

It looks like a bug but since both django and memcached are new to me
I wanted to check if anyone else can corroborate this before filing it
with the django folks.

FWIW, I tried patching the cache_db.py to:
"cache.set(self.session_key, self._session, int(time.time()) +
settings.SESSION_COOKIE_AGE)"
but just managed to get Django crashing after sending hundreds of
requests for the same key to memcached on a simple page load....
probably best if I leave the patching to the experts at this stage ;)

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


Reply via email to