Development Articles RSS


Flushing Memcached

October 11, 2007

In getting my blog off the ground, going through the 'minor-update, publish, release' cycle, I found myself needing to flush memcached to see my changes on my production server (I didn't want to wait 15 minutes for the cache to expire).

A quick google yielded the following technique:

$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
flush_all
OK
quit
Connection closed by foreign host.

I thought that was pretty helpful.

The Test Client Session

January 23, 2008

I just ran into a funny little quirk when writing a unit test in Django.

I had the following code:

data = {} # my data omitted
self.client.session['product_response'] = {
    
'message': 'Test message.'
    
}
self.client.session.modified = True
self.client.session.save()
response = self.client.post('/foo/', data)

When running this test it failed because request.session[ 'product_response' ] wasn't a valid key. I dropped into a shell and discovered:

>>> client.session['foo'] = 1
>>> 'foo' in client.session
False
>>> client.session is client.session
False

So that had me puzzled. After fiddling around, I found that I could get things to work right if I grabbed the session as a local variable and worked against that.

So my test code ended up looking like this:

data = {} # my data omitted
s = self.client.session
s['product_response'] = {
    
'message': 'Test message.'
    
}
s.modified = True
s.save()
response = self.client.post('/foo/', data)

And that did the trick.

I haven't explored why this is the case, but it was interesting enough to me that I thought I'd share it.

doug.