          try:
              if cursor.fetchone():
                  cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % self._table, [encoded, str(exp), key])
              else:
                  cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % self._table, [key, encoded, str(exp)])
          except DatabaseError:
              # To be threadsafe, updates/inserts are allowed to fail silently
              pass
          else:
              transaction.commit_unless_managed()
 
</s> remove             if cursor.fetchone():
 </s> add             if mode == 'set' and cursor.fetchone():
                if mode == 'add':
                    cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % self._table, [key, encoded, str(exp)])
          try:
              if cursor.fetchone():
                  cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % self._table, [encoded, str(exp), key])
              else:
                if mode == 'add':
                    cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % self._table, [key, encoded, str(exp)])
          except DatabaseError:
              # To be threadsafe, updates/inserts are allowed to fail silently
              pass
          else:
              transaction.commit_unless_managed()
keep keep keep keep replace keep keep keep keep keep
 Fixed #4831 -- Added an "add" cache key method, for parity with memcached's
API. This works for all cache backends. Patch from Matt McClanahan.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6572 bcc190cf-cafb-0310-a4f2-bffc1f526a37 
django/core/cache/backends/db.py