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 8949951

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:20:20+00:00 2026-06-15T13:20:20+00:00

I’m getting some weeeeeeird behavior with my cache in django. If I refresh the

  • 0

I’m getting some weeeeeeird behavior with my cache in django. If I refresh the page, I get the same value over and over(which is an int that’s supposed to get incremented every time the view gets hit). But, if I login in another browser with the same username/passwd, I see an incremented number, but it doesn’t increment until I log in again. I never logged out either, just left the page open and logged in from another browser.

Edit: It also increments every time I change the url(e.g. add a slash to stay in same view) Browser cache is supposedly disabled.

Edit 2: Now super weird: it started working on every refresh when I opened a new page in another browser after adding the @never_cache decorator to my view, but then when i switched back to apache/wsgi, it stopped working again (yes, i restarted apache).

Edit 3: Randomly started working under apache now… but in chrome if i set the url to have the trailing /, it goes back to the number it was before x refreshes. But, if I refresh in chromium with trailing /, it keeps incrementing. Would this be a browser or apache cache?

View code:

from django.core.cache import cache

if cache.get('counter') != None:#0 needs to let this pass
    cache.incr('counter')
else:
    cache.set('counter', 0)
return HttpResponse(cache.get('counter')) 

Relevant settings:

 MIDDLEWARE_CLASSES = (
'django.middleware.cache.UpdateCacheMiddleware',          #cache middleware
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',)      #cache middleware

CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
CACHES = {'default':{
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211', #this is the default port for memcache
        'TIMEOUT': '1800' #30 Minutes
        }
    }

I’ll be closely monitoring this question for any requests for more info about my problem, so comments will get answered quickly.

Picture is all that I can use to describe the behavior.

  • 0 0 Answers
  • 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-06-15T13:20:22+00:00Added an answer on June 15, 2026 at 1:20 pm

    In your MIDDLEWARE_CLASSES you have django.middleware.cache.UpdateCacheMiddleware and django.middleware.cache.FetchFromCacheMiddleware which are for page caching. That’s why you saw the behavior go away when you used the @never_cache decorator.

    You may have been seeing the weird slash/no-slash problem because those pages were still in the cache(I’m not 100% sure if the decorator interacts with the fetching from cache part).

    If you flush your cache, or even take the middlewares out for testing, and try again, I’d bet you would see a consistent incrementing that you expect.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary

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.