During my Django application, I frequently run exactly the same query on my small database (e.g. every ten seconds). Then i create an MD5 sum within the queryset I receive and compare that towards the MD5 sum I produced in the earlier run. If both of them are equal, the information hasn't transformed and the site doesn't need upgrading.

As I do that, the information within the DB might change.

However, the query returns exactly the same queryset, apparently because of query caching.

How do i disable the query cache and explicitely execute the query around the DB ?

Query caching only is applicable within a QuerySet. Quite simply, should you assess the same queryset object two times, query caching will operate. But when you do a question every ten seconds, most probably this really is using a cron that spawns a brand new process every time, so there's not a way Django will cache anything.

It's possible that the database's own cache can come into operation if you are frequently carrying out the identical query. You should think about the documentation for the DBMS to determine how you can manage that correctly.

I discovered behavior which i thought was some type of caching, however it switched to be database transactions kidding me.

I'd the issue whereby another process, products were get put into the database, and that i desired to monitor progress from the other process, and so i opened up up a django spend and released the next:

>>> MyData.objects.count()

>>> MyData.objects.count()

The worthiness wasn't altering, despite the fact that it really is at the database. I recognized that a minimum of with generate an income had MySQL &lifier django setup which i is at a transaction and would only visit a "snapshot" from the database at that time I opened up the transaction.

Owing to sights in django, I'd autocommit behavior defined, it was acceptable for each view to simply visit a snapshot, as next time a view was known as it might be inside a different transaction. However for a bit of code which was not instantly carrying out, it wouldn't use whatever alterations in the db except individuals which were produced in this transaction.

Just thought I'd toss this answer set for anybody who will come this situation.

To resolve, commit your transaction, which may be by hand done like so:

>> from django.db import transaction
>> transaction.enter_transaction_management()
>> transaction.commit() # Whenever you want to see new data

The hyperlink you provide towards the Django Documentation suggests the following:

>>> print [e.headline for e in Entry.objects.all()]
>>> print [e.pub_date for e in Entry.objects.all()]

produces two queries towards the database, although:

>>> queryset = Poll.objects.all()
>>> print [p.headline for p in queryset] # Evaluate the query set.
>>> print [p.pub_date for p in queryset] # Re-use the cache from the evaluation.

uses the query cache, when you are being able to access exactly the same evaluation results.

How complicated are the QuerySet objects?

I believe the easiest option would be to produce a new QuerySet object after which review it. This way you will not hit the QuerySet cache whatsoever.

Thanks greatly for the solutions, your replies helped me have a couple of steps back and re-think.

To be able to test caching on the DBMS level, I disappeared from Django and used a spend script I anyway had handy to periodically query data from the SQLite db, as i added data inside a second spend session. The brand new data turned up within the periodic queries immediately after I added them, so no query caching here.

This simplified it lower towards the Django part. The code involved is not so complex along with a little log output along with a code review revealed the issue: The query used to get the queryset utilized in use produce the MD5 sum had a mistake and was always empty. Therefore, the MD5 sum was always exactly the same. Did indeed seem like a cached result - information is altering, however the queryset stays exactly the same. The issue didn't show within the application, like a different query was adopted to acquire data displayed there.

Lesson learned: If you are completely puzzled, have a take a step back and re-think your presumptions.

Many thanks! :-)