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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:58:36+00:00 2026-06-12T10:58:36+00:00

It looks like temporary variables are also cached when using NDB. class MyModel(ndb.Model) def

  • 0

It looks like temporary variables are also cached when using NDB.

class MyModel(ndb.Model)

    def __init__(self, *args, **kwds):
        self._temporary = []
        ndb.Model.__init__(self, *args, **kwds)

Is there a way not to store the temporary / helper variables in the cache?

EDIT:

Here is a simple test case proving my problem:

#Python imports
import unittest

# GAE imports
from google.appengine.ext import testbed
from google.appengine.datastore import datastore_stub_util
from google.appengine.ext import ndb


class TestModel(ndb.Model):

    username = ndb.StringProperty()

    def __init__(self, *args, **kwds):
        self._temp = []
        ndb.Model.__init__(self, *args, **kwds)

class TestModels(unittest.TestCase):

    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        self.testbed.init_taskqueue_stub()
        self.testbed.init_urlfetch_stub()
        self.testbed.init_mail_stub()
        self.testbed.init_images_stub()
        self.testbed.init_blobstore_stub()

        self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1)
        self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)

        self.testbed.init_memcache_stub()
        self.testbed.setup_env(app_id='ndb-test')

    def tearDown(self):
        self.testbed.deactivate()

    def test1(self):

        test_model = TestModel()
        test_model.username = 'Tom'
        test_model._temp = 'Temporary'
        test_model.put()

        test = TestModel.query().fetch(10)

        self.assertEqual(1, len(test))

        test = test[0]

        self.assertEqual('Tom', test.username)
        self.assertEqual([], test._temp)

The last line of the test self.assertEqual([], test._temp) fails even though I would expect it to pass.

Is there a way to either not store temporary / helper model properties or have a cleaver way of resetting them every time model is loaded from cache?

  • 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-12T10:58:38+00:00Added an answer on June 12, 2026 at 10:58 am

    NDB has a couple of caches – instance memory and memcache. In instance memory, the actual entity itself is cached, so the same entity object will be returned for multiple get calls within the same request.

    As long as you’re using NDB with caching enabled, this is something you’ll have to deal with – for instance, by not storing ‘temporary’ data on an entity in the first place.

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

Sidebar

Related Questions

Looks like this question has been asked thousand times already, but each person's configuration
Looks like while( condition ) { //do stuff } is completely equivalent to for(
Looks like ExpressionTrees compiler should be near with the C# spec in many behaviors,
Looks like there is no Load event for usercontrol on the CF. I'm used
Looks like XSD.exe is not delivered as a part of Visual Studio 2010. what
Looks like dynamic memory allocation without garbage collection is a way to disaster. Dangling
Looks like operator new and operator new[] have exactly the same signature: void* operator
Looks like the options are Propel, Doctrine, and ActiveRecord, others?, but I am only
Looks like a dumb question, but I tried the following (where Me is a
It looks like this block directly flushes the output. What's the practical use of

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.