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

  • Home
  • SEARCH
  • 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 9161077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:53:13+00:00 2026-06-17T13:53:13+00:00

This might be a python question. It is a noobish one to be sure.

  • 0

This might be a python question. It is a noobish one to be sure.

A client requests a calculation-intensive page [page-1] and will ultimately request a second calculation-intensive page [page-2], which can be calculated the instance the request for page-1 is known. I don’t want to calculate each set of data before serving page-1 because it will significantly slow down the performance of the initial response.

I do want to calculate the value for page-2 while the client reads page-1. The client also might click on some buttons which cause a response that provides a different view of page-1 data, but don’t necessitate an intensive calculating. Eventually but not necessarily immediately, the client will ask for page-2 and I want to be able to response with a pre-rendered response.

How do I do this?

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

    As mentioned in the comments, it sounds like you’re going to need to handle this with an asynchronous background task, saving the result in the Django low level cache. I would personally use celery for the task queue.

    Basically, after page one is requested, you would add an asynchronous task to start the page 2 calculations, storing the result in the cache. So, when page 2 is requested, you check for the pre-rendered response in the cache, and if it doesn’t exist, you could calculate the value synchronously.

    So, your code would look something like this (the task would be in a task.py file in your app, but this should give you a general idea):

    from celery import task
    from django.core.cache import cache
    
    def page_two_calculation(arg1, arg2):
        return arg1 + arg2
    
    @task
    def page_two_task(arg1, arg2):
        result = page_two_calculation(arg1, arg2)
        cache_key = "page-two-%s-%s" (arg1, arg2)
        cache.set(cache_key, result)
    
    def page_one(request, arg1, arg2):
    
        # Start the page two task
        page_two_task.delay(arg1, arg2)
    
        # Return the page one response
        return HttpResponse('page one')
    
    def page_two(request, arg1, arg2)
        cache_key = "page-two-%s-%s" (arg1, arg2)
        result = cache.get(cache_key)
        if result is None:
             # the result will only be None if the page 2 calculation
             # doesn't exist in the cache, in which case we'll have to
             # return the value synchronously.
             result = page_two_calculation(arg1, arg2)
        return result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a little too much direct question. New to Python I am
This might seem like a very easy question for some of you folks, but
This might be a simple question but I've searched and searched and can't find
This might be a naive question. However, I am just trying to understand why
This might be a very basic question but it confuses me. Can two different
This might sound like a stupid question but just trying to learn something here.
This might be a general mvp places and activities question, but the show case
This might be a really trivial one. Is File storage OS dependant ? Why
I'm a python newbie so I apologize in advance if this question has been
This might be more of a CYGWIN question than a Nodejs but here goes.

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.