python-3.x - uwsgi.cache_set() 不在 mule 进程内的单独线程中工作
问题描述
uwsgi.cache_set('test', data)
为了实验,我在 mule 进程中设置了一个缓存。缓存按预期设置。
现在我生成一个线程,我可以从中访问该缓存
线程在以下位置启用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()
问题是为什么会发生这种情况以及如何从线程内部设置缓存。
解决方案
好的,好像我使用了错误的函数 ( cache_set
) 而不是cache_update
.
uwsgi.cache_set(key, value[, expire, cache_name])
在缓存中设置一个值。如果密钥已设置但未过期,则不会设置任何内容。
uwsgi.cache_update(key, value[, expire, cache_name])
更新缓存中的值。这总是设置 key,无论它之前是否已经设置,以及它是否已过期。
推荐阅读
- django - 禁止直接分配到多对多集合的前端。改用 variant.set()
- python - 检索图像的隐藏 URL(没有附件的图像,仅 url)
- visual-studio - 如何让 ApprovalTests 创建 UTF-8 文件
- c - 代码由于类型错误而无法编译但未给出任何运行时错误的示例
- typescript - 没有明确未定义的打字稿可选字段
- django - 根据先前选择的选项显示 Django Fieldset 值?
- reactjs - 如何在 FieldArray 中包含不同值的数组的 yup 验证中添加错误消息?
- amazon-redshift - Redshift 将一个值转换为 bigint 会舍入一个值
- oracle - 将日期差异转换为带有时间戳的日期
- api - Autotask Rest API 工单收费状态