uwsgi.cache_set()不在mule进程内的单独线程中工作

问题描述 投票:0回答:1

为了实验,我在mule进程中设置了一个缓存uwsgi.cache_set('test', data)。缓存按预期设置。

现在我生成一个线程,我可以从中访问该缓存


uwsgi.ini中启用了线程:

[uwsgi]
threads = 4

mule.py

#Threaded function
def a_function():
    uwsgi.cache_set('test', b'NOT OK') <- Nothing happens here
    cache_return = uwsgi.cache_get('test') <- Returns b'OK' which means the cache did not overwrite the previous value.

if __name__ == '__main__':
    cache = uwsgi.cache_set('test', b'OK')  <- Works here
    cache_return = uwsgi.cache_get('test') <- Return b'OK', as expected
    t = Thread(target=a_function)
    t.start()

问题是为什么会发生这种情况,如何从线程内部设置缓存。

python-3.x multithreading caching uwsgi
1个回答
0
投票

好吧,好像我使用了错误的函数(cache_set)而不是cache_update

uwsgi.cache_set(key, value[, expire, cache_name])

在缓存中设置一个值。如果密钥已设置但未过期,则不会设置任何内容。


uwsgi.cache_update(key, value[, expire, cache_name])

更新缓存中的值。这始终设置密钥,无论它是否已经设置,是否已经过期。

© www.soinside.com 2019 - 2024. All rights reserved.