Issue #8 resolved

Tests/fixture loading should invalidate cache.

Matthew Schinckel
created an issue

I'm still investigating further, but it seems that I have tests failing because the fixtures that are being loaded as part of the test setup are not being reflected in the returned data when the johnny-cache middlewares are installed.

I think it is because the fixtures are loaded in without the cache being invalidated. Loading fixtures should invalidate the cache.

There are two ways that fixtures are loaded, that I am aware of: the management command loaddata, and as part of the test creation in django.

Comments (7)

  1. Matthew Schinckel reporter

    At first glance, it seems like we should just override the two management commands. However, this seems like a sloppy approach. I wonder if there is a signal we can watch for?

  2. Matthew Schinckel reporter

    Okay, now I am confused. It _does_ invalidate the cache on fixture loads (apparently), but I have a couple of instances where I still get incorrect data back. Searching deeper.

  3. Matthew Schinckel reporter
    • changed status to new

    Aha! It looks like the fixture is not being re-loaded correctly!

    If I put in a specific:

    invalidate('table_name')

    in my tearDown() method in a TestCase, then that fixes the issue I was seeing.

    In fact, putting in a cache invalidation as a pre_save hook fixes it too. Is there any reason not to have the cache invalidated before the save? Does this mean if the save fails, the cache will have been needlessly invalidated? Is this behaviour I am seeing the result of a cache hit on a write to database - which should never happen?

  4. Anonymous

    Fixtures can get complicated, because a lot of times they will run inside a transaction. Could that impact the weirdness you're seeing, or are you using the TransactionTestCase (which, ironically, does not use transactions)?

    (This was by jmoiron, but I wasn't logged in)

  5. Log in to comment