【问题标题】:Why is there a memcache delete at the end of this NDB put operation?为什么在这个 NDB put 操作结束时有一个 memcache 删除?
【发布时间】:2014-03-16 17:10:28
【问题描述】:

我只是在 Google App Engine 上试验 Appstats 和 NDB。

我知道 put 之后的立即 get 将来自本地内存缓存,但为什么会有 memcache 删除操作?

这是所有代码:

import webapp2
from google.appengine.ext import ndb

class Specs(ndb.Model):
    make = ndb.StringProperty()
    model = ndb.StringProperty()
    doors = ndb.IntegerProperty()
    wheels = ndb.IntegerProperty()

class Car(ndb.Model):
    _use_memcache = True
    _use_cache = True
    specs = ndb.LocalStructuredProperty(Specs)

class MainHandler(webapp2.RequestHandler):
    def get(self):
        my_car = Car(id='some-car')
        specs = Specs(
          make = "Volvo",
          model = "240",
          doors = 5,
          wheels = 4
        )
        my_car.specs = specs
        result = my_car.put()

        my_car_by_get = result.get()

        self.response.write('Saved car')

app = webapp2.WSGIApplication([
    ('/', MainHandler),

], debug=True)

还有 Appstats 时间线:

【问题讨论】:

    标签: python google-app-engine memcached app-engine-ndb


    【解决方案1】:

    当您使用 NDB 时,每个 put() 都会调用 memcache.Delete(),因为这是自动缓存,这是设计使然。如果您想在缓存方面获得更好的控制或不同的行为,您可以阅读有关 NDB caching 的更多信息。

    【讨论】:

    • 那么您的意思是,在这个特定的示例中,操作顺序可能不是最优的,但这样做是为了适应更广泛更通用的机制?
    • 我的意思是,即使你有最简单的操作,比如只有 .put,memcache delete 也会被调用.. 之前或之后做什么都没关系..
    • 阅读ndb源代码。 mc 删除是为了避免竞争条件。
    • @Guido 至少我对它调用 mc delete 的事实并没有完全错误:) 你介意写一个更有效的答案,我会删除这个:/
    猜你喜欢
    • 2011-11-05
    • 1970-01-01
    • 2017-04-18
    • 2019-06-02
    • 2010-10-01
    • 2020-01-17
    • 1970-01-01
    • 1970-01-01
    • 2012-06-04
    相关资源
    最近更新 更多