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 8195897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:17:48+00:00 2026-06-07T05:17:48+00:00

I am building a web application on google app engine using python and jinja2.

  • 0

I am building a web application on google app engine using python and jinja2. I have a website where users can write posts and I have 15 main categories and each of those has 4 divisions. Now I want to implement memcache because I have a 20:1 reader to poster ratio but how can I do it without making 60 different keys? Should I just do it that way? Or should I hit the database and sort the results and have some parameters on the function that gets those results like so:

def posts_cache(update = False, category = None, sport = None):
        key = 'main'
        posts = memcache.get(key)
        if posts is None or update:
                logging.error("DB QUERY")
                posts = db.GqlQuery("SELECT * "
                                        "FROM Post "
                                        "ORDER BY created DESC "
                                        "LIMIT 100",
                                         key)
                posts = list(posts)
                memcache.set(key, posts)
        if category and sport:
            sportcatlist = []
            for post in posts:
                     if post.category == category:
                         if post.sport == sport:
                             sportcatlist.append(post)
            return sportcatlist
        elif category:
            categorylist = []
            for post in posts:
                     if post.category == category:
                            categorylist.append(post)
            return categorylist
        elif sport:
            sportlist = []
            for post in posts:
                     if post.sport == sport:
                            sportlist.append(post)
            return sportlist
        return posts

Or is there a more efficient way to do it?

  • 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-07T05:17:49+00:00Added an answer on June 7, 2026 at 5:17 am

    One possible way to do this more efficiently would be to have list of posts per category and content of the post cached separately by predefined key format (‘category_%s(category_name)’ for categories and ‘post_%s(post_key)’. First contains list posts’ keys (possibly with some meta-information like last-updated-date if needed, the second – content of the post by key). Under ‘key’ I mean either serialized datastore key or id in datastore or something else you could use to simply read post from datastore if it’s not in memcache. Storing each particular post and categories content separately will be efficient even under huge load including updates as for updated post you invalidate single memcache key, by adding/deleting post you invalidate list for single category, all other memcached data still in place so other requests handled by memcache only. As appengine enforce limits on amount of data can be stored in memcache, it will delete older and rare hit items and keep often-use which is exactly what you need and scales perfectly fine, approach you described will not give you this.
    Hope it helps.

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

Sidebar

Related Questions

I am building a web application on Google App Engine that requires users to
I am building a web application as college project (using Python), where I need
I am building a web application and have been told that using object oriented
I'm currently building a SmartGWT-based web application (using the Portlet Layout). So I have
I'm currently building a web application using Google Maps. Unfortunately, I've reached the absolute
I'm building a web-application that lets users login with a google-apps account. I need
I'm building a web-application in JavaScript using the dojo framework. I want to create
I am building a Web Application using asp.net (C#). I come from windows forms
I am building a web application that will need to allow users to save
I am building a web application using ASP.NET MVC that has two very distinct

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.