Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6145133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:45:11+00:00 2026-05-23T18:45:11+00:00

I’ve got a pretty simple site where I’m using the page_cache decorator. I have

  • 0

I’ve got a pretty simple site where I’m using the page_cache decorator.
I have a cronjob that checks for new data and processes it if it’s available.
(This is run using management commands executed with crontab)

I want to then clear all the page caches when new data is processed.

I’m looking at the documentation here:
https://docs.djangoproject.com/en/stable/topics/cache/

and found cache.clear(), which seems to be what I want.
I’ve added a flag to the data processing portion and execute cache.clear() when new data is found.

However, after the command runs the cache isn’t cleared.
(I’ve cleared the browser cached and checked to be sure it’s not the browser)

Does cache.clear() not work in to clear all cached pages?

I’m using the DatabaseCache, so I guess I could go in and clear the cache table manually, but is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:45:12+00:00Added an answer on May 23, 2026 at 6:45 pm

    I’ve had this problem with an SQLite database cache – the clear() method doesn’t clear the cache although it works fine with a MySQL database cache. It seems that a SQLite cache needs a call to django.db.transation.commit_unless_managed() after the DELETE from [table] statement is run.

    I have been using multiple caches since before official support was added into core as part of 1.3 and so have a wrapper round several of the cache calls – including clear() – so I was able to override this method and include the commit_unless_managed(). I think I should probably log it as a bug.

    Here’s the outline of the code I’m using to flush a memcache cache (the default cache in django.core.cache) and a database cache stored in the cache_table of the settings.DATABASES['cache_database'] database.

    from django.db import connections, transaction
    from django.core.cache import cache # This is the memcache cache.
    
    def flush():
        # This works as advertised on the memcached cache:
        cache.clear()
        # This manually purges the SQLite cache:
        cursor = connections['cache_database'].cursor()
        cursor.execute('DELETE FROM cache_table')
        transaction.commit_unless_managed(using='cache_database')
    

    Rather than being lazy and hard coding it the way I have it should be pretty easy to get the values from settings.CACHES and django.db.router.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I have just tried to save a simple *.rtf file with some websites and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.