修复并发场景下缓存push操作抛出异常的问题#3200
Open
augushong wants to merge 1 commit into
Open
Conversation
改动内容 think\cache\Driver::push() 方法,将非数组缓存值的处理从抛出异常改为重置为空数组继续执行。 收益 - 消除并发场景下的致命错误:Cache::tag()->set() 是框架推荐的标准用法,在并发请求下不再抛出 InvalidArgumentException 导致业务 500 - 改动极小:仅修改 1 行代码,不影响任何公共 API、方法签名、正常场景下的行为 - 所有驱动统一受益:File、Redis、Memcache、Memcached、Wincache 均继承基类 push(),无需逐个处理 - 正常场景零影响:当缓存值为数组时(绝大多数情况),!is_array 分支不走,行为完全不变 注意事项 - tag 集合可能被意外重置:触发容错时,tag 集合从已有索引重置为仅含当前值,之前记录的缓存 key 成为孤儿,Cache::tag()->clear() 可能漏清 - 孤儿缓存需要过期时间兜底:未设置过期时间的孤儿缓存将永久残留,建议使用 tag 缓存时配合合理的过期时间
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
改动内容
think\cache\Driver::push() 方法,将非数组缓存值的处理从抛出异常改为重置为空数组继续执行。
收益
注意事项