Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only insert cache item into the database when there is no item already i... #4586

Closed
wants to merge 2 commits into from

Conversation

bobkarreman
Copy link

I made a change to the cache db backend to only do an insert when it's needed.

When there is already an result and its not expired the insert is going to fail so it could be skipped.

Or am I missing something?

@timgraham
Copy link
Member

There are some failing tests with this change:

======================================================================
FAIL: test_add (cache.tests.DBCacheTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/code/django/tests/cache/tests.py", line 248, in test_add
    self.assertFalse(result)
AssertionError: True is not false

======================================================================
FAIL: test_forever_timeout (cache.tests.DBCacheTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/code/django/tests/cache/tests.py", line 500, in test_forever_timeout
    self.assertEqual(added, False)
AssertionError: True != False

@bobkarreman
Copy link
Author

You are right sorry.
This should fix it!

@timgraham
Copy link
Member

buildbot, add to whitelist.

@timgraham
Copy link
Member

I think the code could be written this way to avoid a race condition where the key is deleted after the "SELECT cache_key, expires..." query and before the "INSERT" query.

@timgraham timgraham closed this May 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants