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 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

Related Questions

(This question specifically in C#, but applies generally to .NET) I have a largish
I've asked this before for Java , but this applies specifically to J2ME. Is
I'm not even sure this is entirely programming related...but here goes: I need to
This is specifically related to ARM Neon SIMD coding. I am using ARM Neon
This question is specifically related to overriding the equals() method for objects with a
Unlike the other posts about the task delete all tables, this question is specifically
This is specifically related to the accepted answer of another question I asked .
First, this has never worked before, so it is not specifically related to VS
(Related to this question .) I'm looking for a wysiwyg editor, but which outputs
I know I have seen an article this somewhere (specifically related to Azure too!)

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.