uwsgi.cache_set()在a子进程内的单独线程中不起作用

时间:2019-03-07 16:37:01

标签: python-3.x multithreading caching uwsgi

为了进行实验,我在a子进程中设置了缓存 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()

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

1 个答案:

答案 0 :(得分:0)

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

  

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

     

在缓存中设置一个值。 如果密钥已经设置但尚未过期,   它没有设置任何内容


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

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

相关问题