Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 谷歌应用引擎Memcache没有快速更新_Google App Engine_Optimization_Memcached - Fatal编程技术网

Google app engine 谷歌应用引擎Memcache没有快速更新

Google app engine 谷歌应用引擎Memcache没有快速更新,google-app-engine,optimization,memcached,Google App Engine,Optimization,Memcached,我在谷歌应用程序引擎(Python)中使用Memcache已经有一段时间了,它通常工作得很好。在过去的几天里,虽然我注意到一些代码,比如下面的例子,当我更新数据库条目后立即更新它时,它没有及时得到它。这是因为在数据库中存储条目所需的时间长吗?有什么解决办法吗 # I store the comment here c = Comment(content = content, submitter = submitter, group_id=int(group_id), user_id = user

我在谷歌应用程序引擎(Python)中使用Memcache已经有一段时间了,它通常工作得很好。在过去的几天里,虽然我注意到一些代码,比如下面的例子,当我更新数据库条目后立即更新它时,它没有及时得到它。这是因为在数据库中存储条目所需的时间长吗?有什么解决办法吗

# I store the comment here 
c = Comment(content = content, submitter = submitter, group_id=int(group_id), user_id = user_id)
c.put()
# Right after I store the comment I refresh the cache
comment_cache(int(group_id), True)

通常最新的注释不在缓存中。

由于最终的一致性,如果
comment\u cache()
运行一个查询(即,不按键获取),则您所描述的内容是预期的

一些解决方案:

  • 更改
    comment\u cache()
    以将
    c
    作为参数,以便它明确了解它:
    comment\u cache(int(group\u id),True,c)
  • 在任务队列中运行
    comment\u cache()
    。目前还不能保证它会收到新的评论,但因为它会在一段时间后运行,所以可能会

  • 由于最终的一致性,如果
    comment\u cache()
    运行一个查询(即,不按键获取),那么您所描述的内容是预期的

    一些解决方案:

  • 更改
    comment\u cache()
    以将
    c
    作为参数,以便它明确了解它:
    comment\u cache(int(group\u id),True,c)
  • 在任务队列中运行
    comment\u cache()
    。目前还不能保证它会收到新的评论,但因为它会在一段时间后运行,所以可能会

  • 我和你有同样的问题

    当我在数据库中添加值时,我更新了缓存,但由于查询运行时间较长,最后插入的值没有插入到缓存中

    我的解决方案:我有一个更新缓存的函数,现在我添加了我想放在数据库中的值作为参数,如下所示:

    def get_values_from_cache_or_database(particular_value = None, update = True):
      key = 'my_key'
    
      values = memcache.get(key)
        if values is None or update:
          values = db.GqlQuery("SELECT * FROM Table")
          values = list(values)
          if update:
            if particular_value not in values:
              # if we are here, particular_value isn't in your data base (because time 
              # request is  long) but we want the particular_value in the cache so we add 
              # it manually  
              values.append(particular_value)
      memcache.set(key, values)
      return values
    
    例如,我们将一个值“value1”设置为:
    value1.put()
    我们调用此函数以“value1”作为参数刷新缓存:
    从\u缓存\u或\u数据库中获取\u值(value1,True)

    然后,我们将为您的缓存添加最新的附加值

    我和你有同样的问题

    当我在数据库中添加值时,我更新了缓存,但由于查询运行时间较长,最后插入的值没有插入到缓存中

    我的解决方案:我有一个更新缓存的函数,现在我添加了我想放在数据库中的值作为参数,如下所示:

    def get_values_from_cache_or_database(particular_value = None, update = True):
      key = 'my_key'
    
      values = memcache.get(key)
        if values is None or update:
          values = db.GqlQuery("SELECT * FROM Table")
          values = list(values)
          if update:
            if particular_value not in values:
              # if we are here, particular_value isn't in your data base (because time 
              # request is  long) but we want the particular_value in the cache so we add 
              # it manually  
              values.append(particular_value)
      memcache.set(key, values)
      return values
    
    例如,我们将一个值“value1”设置为:
    value1.put()
    我们调用此函数以“value1”作为参数刷新缓存:
    从\u缓存\u或\u数据库中获取\u值(value1,True)

    然后,我们将为您的缓存添加最新的附加值

    好的,谢谢你的帮助。随着注释数据库变得越来越大,您知道缓存是否需要更长的时间才能保持一致吗?我的理解是,数据存储的大小与性能无关,因此不应该随着它的增长而花费更长的时间。好的,谢谢您的帮助。随着注释数据库变得越来越大,您知道缓存是否需要更长的时间才能保持一致吗?我的理解是,数据存储的大小与性能无关,因此不应该随着它的增长而花费更长的时间。