Duplicate Key Error in Cache

35 views
Skip to first unread message

gamingdroid

unread,
Jul 12, 2011, 12:09:00 PM7/12/11
to Django users
I ran into this problem using django core's database cache:

ERROR: duplicate key value violates unique constraint "cache_pkey"
STATEMENT: INSERT INTO "cache" (cache_key, value, expires) VALUES (E':
1:cms-menu_nodes_en-us_1', E'gAJdcQEoY21lbnVzLmJhc2UKTmF2aW
LOG: server process (PID 8453) was terminated by signal 9: Killed
LOG: terminating any other active server processes
LOG: all server processes terminated; reinitializing
FATAL: could not create shared memory segment: Cannot allocate memory
DETAIL: Failed system call was shmget(key=5432001, size=29278208,
03600).

I looked in the table and sure enough, there is an entry for the key ':
1:cms-menu_nodes_en-us_1'. I found a similar issue here (http://
stackoverflow.com/questions/1189541/django-cache-set-causing-duplicate-
key-error), but was unable to exactly understand what the issue is.

Sounds like a bug in django core, since if a key exist, it should
update the record. It looks as if somebody posted a ticket here
(https://code.djangoproject.com/ticket/11569), but not entireloy sure
if it is related. This problem sort of renders the database backend
useless. I would fix it if I knew how and contribute back, but really
don't know how.

Anyone have any ideas or suggestions?

Issac Kelly

unread,
Jul 12, 2011, 9:29:22 PM7/12/11
to Django users
I would guess your quickest way forward is to change backends, as it
appears that this is a larger issue with database transactions between
threads, which is a couple of years old.

I've been tinkering with LocalMemCache for a really small site, and
django-redis-cache as a toy, I know that some have used it in
production, but I haven't, and adding another piece to your deployment
isn't always a good idea.

It's also possible that memcached is a good fit for what you're doing.

Andre Terra

unread,
Jul 13, 2011, 6:37:55 AM7/13/11
to django...@googlegroups.com
And memcached isn't hard to setup at all!

Cheers,
André

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


Cal Leeming [Simplicity Media Ltd]

unread,
Jul 13, 2011, 9:55:02 AM7/13/11
to django...@googlegroups.com
May I ask why you are using a database cache, rather than something like memcache??

Cal

gamingdroid

unread,
Jul 13, 2011, 10:59:45 AM7/13/11
to Django users
I'm memory constrained and therefore memcache is not an option. The
pages makes a lot of independent SQL queries that is better handled
through one sql call via the db cache backend.

I suppose I could roll my own, but find it odd that somebody hasn't
fixed it. I would fix it myself, if I knew what was going on in there,
but I'm pretty new to Django.

On Jul 13, 9:55 am, "Cal Leeming [Simplicity Media Ltd]"
Reply all
Reply to author
Forward
0 new messages