Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
高效的缓存设置,当操作
value = db['key']
或value = db.get('key)
时将直接返回对db中'key'的缓存引用,在短时间内(一秒内)操作value会直接改变db的值。
如value是个字典,可以直接对
value['xx'] = xxx
。但这份缓存一般只会存在1秒钟,超过这个时间周期后操作value对象将不会更新到db。
更通用的写法是:
db['key']['xx'] = xxx
可以确保值被正确更新至db。