在 GAE 中使用内存缓存时,我很少注意到这种奇怪的行为。我在内存缓存中设置了一个值,当我尝试检索相同的值时,我得到的是 None 而不是原始值。内存缓存值不可能在这么短的时间内过期。当我在 memcache 中设置值时,我确实确保返回 True。还有什么会导致内存缓存值丢失?这是一种常见的系统行为吗?
代码示例:
用于设置值
cache_set = memcache.set(matrix_name+'-'+str(m)+","+str(n),data[n],namespace=uuid)
while cache_set == False :
sleep(0.1)
logging.error(" Cache Set failed. Retrying for %s %s",matrix_name,str[m,n])
cache_set = memcache.set(matrix_name+'-'+str(m)+","+str(n),data[n],namespace=uuid)
获取值
memcache.get(matrix_name+'-'+str(m)+","+str(n),namespace=uuid)
最佳答案
Memcache 本质上是不可靠的。它不保证将数据保留多长时间,甚至不保证它会保留数据。您不应该期望它总是会在某个最短时间内返回存储的数据。
关于google-app-engine - Google App Engine 内存缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5112685/