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

The Archive Base Latest Questions

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

This is specifically related to the Google App Engine Memcache API, but I’m sure

  • 0

This is specifically related to the Google App Engine Memcache API, but I’m sure it also applies to other Memcache tools.

The dictionary .get() method allows you to specify a default value, such as dict.get(‘key’, ‘defaultval’)

This can be useful if it’s possible you might want to store None as a value in a dictionary.

However, the memcache.get() does not let you to do this. I’ve modified my @memoize decorator so it looks like this:

def memoize(keyformat, time=1000000):

    """Decorator to memoize functions using memcache."""
    def decorator(fxn):
        def wrapper(*args, **kwargs):
            key = keyformat + str(args[1:]) + str(kwargs)
            from google.appengine.api import memcache
            data = memcache.get(key)
            if Debug(): return fxn(*args, **kwargs) 
            if data:
                if data is 'None': data =  None
                return data
            data = fxn(*args, **kwargs)
            if data is None: data = 'None' 
            memcache.set(key, data, time)
            return data
        return wrapper
    return decorator  

Now I’m sure there’s a good argument that I shouldn’t be storing None values in the first place, but let’s put that aside for now. Is there a better way I can handle this besides converting None vals to strings and back?

  • 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-11T18:02:41+00:00Added an answer on May 11, 2026 at 6:02 pm

    A possible way to do this is to create new class that defines None for this purpose, and assign instances of this to the cache (unfortunately you cannot extend None). Alternatively, you could use the empty string “”, or avoid storing None/null values altogether (absence of the key implies None).

    Then check for instances of your ‘None’ class when you check the result of mc.get(key) (is None, == "", etc)

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

Sidebar

Ask A Question

Stats

  • Questions 116k
  • Answers 116k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer to control which cells are editable, you will need to… May 11, 2026 at 10:40 pm
  • Editorial Team
    Editorial Team added an answer THIS METHOD IS DEPRECATED SINCE iOS 7.0. There is a… May 11, 2026 at 10:40 pm
  • Editorial Team
    Editorial Team added an answer Well, the most obvious (and the most common) situation would… May 11, 2026 at 10:40 pm

Related Questions

This is specifically related to the Google App Engine Memcache API, but I'm sure
I'm experiencing the same problem in this previous stackoverflow.com post . Specifically, I seem
Greetings! I'm currently porting a web browser plugin from Win32 to MacOSX. One of
This question is specifically related to overriding the equals() method for objects with a
I've got an application here that I wrote many years ago that consists of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.