fix single-flight ,and add UT description verification #69
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.
源码single-flight并不能保证fn只执行一次,可以用我提交的单测去跑一下,发现fn的执行次数并不是一次(而且每次运行次数还不确定),达不到防止缓存击穿的效果。
我的实现思路:map延迟一秒删除,第一个请求更新map,map里面的key全部一秒之后删除,一秒之内的所有请求都从map获取。一秒之后删除map里面一秒钟之前的数据,请求来了再重新更新map,重复如上 步骤。
注:删除数据不一定得一秒钟之后,可以一百毫秒,更具业务可以调整