title: Django cache causes duplicate key error in database?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1189541/django-cache-set-causing-duplicate-key-error">Django cache.set() causing duplicate key error</a>  </p>
  </blockquote>
  
  
  
  <p>I ran into this problem using django core's database cache:</p>
  
  <pre><code>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).
  </code></pre>
  
  <p>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 <a href="https://stackoverflow.com/questions/1189541/django-cache-set-causing-duplicate-key-error">here</a>, but was unable to exactly understand what the issue is.</p>
  
  <p>Anyone have any ideas or suggestions? Sounds like a bug in django core, since if a key exist, it should update the record.</p>
  
  <p><strong>edit:</strong> I should have clarified that the DB was PostgreSQL 8.4.7. Thanks lazerscience.</p>
  
  <p><strong>edit @ Jack M</strong>: I haven't been able to replicate this error, but <strong>believe</strong> the code is in <code>django.core.cache.backends.db.DatabaseCache</code> in a method called <code>set()</code> that calls <code>_base_set()</code>.</p>