-
Notifications
You must be signed in to change notification settings - Fork 11
feat(): support requestCacheIgnoreList #2131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
56637bc to
774e560
Compare
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
Pull Request Test Coverage Report for Build 2904128008
💛 - Coveralls |
packages/brick-http/src/http.spec.ts
Outdated
| }, | ||
| { | ||
| method: "post", | ||
| url: ".*cmdb.instance.PostSearch.*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是什么规则?.* 是正则吗?那中间其他的 . 呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,这边是希望是url能够支持正则匹配的,这个中间的,我这边我应该加个\,去匹配正确的.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
规则在哪定义的?能否直接传正则类型过来?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
但是因为我这边用法是直接用new RegExg() 去做的,这样也是能匹配正确的,这边规则是在visual builder的config那里去定义的,可以直接传正则类型过来,就是为了避免白名单重复相似接口
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的规则是:
- method: GET
uri: .+
- method: POST
uri: ^.+cmdb\.instance\.PostSearch\/.+$准确来说,这里的配置意思是:主动清除缓存的请求白名单。
意思是,命中到这里面名单的请求都不会触发清除缓存动作,否则就触发清除缓存动作(比如PUT/DELETE等请求)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前来看,只需要满足method和uri的匹配规则就够了,至于请求body或返回body的匹配,暂时不需要,以后有需要可以再扩展
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有点拗口🤦♂️,我看错代码实现了。不过没有理解为啥需要「清除缓存」,匹配后不去记录缓存,不就行了?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
说错了,应该是只有匹配的记录才进行缓存,不需要有「清除缓存」的动作
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不是哦,这边是匹配到的接口,应该是后续再去触发的时候,不用缓存那里的数据,而是直接发送请求,因为我们首次进去这边都会缓存一次(原来做法)因为首次都是需要拉取接口的,我这边实现就觉得没必要在第一次就去判断哪些接口需要不进入「缓存列表」,而是在再次触发的时候,清除对应在 requestCacheIgnoreList 的缓存
packages/brick-http/src/http.ts
Outdated
| this.isEnableCache && | ||
| !this.requestCacheWhiteListKeys.has(key) && | ||
| this.requestCache.set(key, promise); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果这个列表的作用是「忽略预览缓存」,那不应该叫「白名单」,白名单是「允许名单内的东西做什么」的意思,所以这里严格上应该叫「黑名单」,不过叫「requestCacheIgnoreList」更容易理解。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,那我这边改一下字段
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requestCacheIgnoreList赞同这个
packages/brick-http/src/http.ts
Outdated
| ); | ||
| if (isExistRequestCacheWhite) { | ||
| this.requestCacheWhiteListKeys.add(key); | ||
| this.requestCache.delete(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看了下对应的卡片,理解需求了。astrid 这里似乎并没有实现「清理缓存」的功能,应该这样?
| this.requestCache.delete(key); | |
| this.requestCache.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不是全清哦,只是对应匹配到的key清除哦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Alren-huang 我看需求是说的「清理所有当前缓存」吧?
774e560 to
1b806d7
Compare
354f922 to
5c00cf1
Compare
packages/brick-http/src/http.ts
Outdated
| public setClearPreviewRequestCacheIgnoreList = ( | ||
| list: ClearPreviewRequestCacheIgnoreListConfig[] | ||
| ): void => { | ||
| this.clearPreviewRequestCacheIgnoreList = list; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setRequestCacheList & requestCacheList
这个命名应该就OK了
setClearPreviewRequestCacheIgnoreList太拗口了
packages/brick-http/src/http.ts
Outdated
| req.method === config.method && | ||
| (!req.uri || new RegExp(req.uri).test(config.url)) | ||
| ); | ||
| if (this.isRender || isExistRequestCache) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里需要添加多一点注释
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好
packages/brick-http/src/http.ts
Outdated
| const isExistRequestCache = this.clearPreviewRequestCacheIgnoreList.some( | ||
| (req) => | ||
| req.method === config.method && | ||
| (!req.uri || new RegExp(req.uri).test(config.url)) | ||
| ); | ||
| if (this.isRender || isExistRequestCache) { | ||
| this.requestCache.set(key, promise); | ||
| } | ||
| if (!this.isRender && !isExistRequestCache) { | ||
| this.requestCache.clear(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const isExistRequestCache = this.clearPreviewRequestCacheIgnoreList.some( | |
| (req) => | |
| req.method === config.method && | |
| (!req.uri || new RegExp(req.uri).test(config.url)) | |
| ); | |
| if (this.isRender || isExistRequestCache) { | |
| this.requestCache.set(key, promise); | |
| } | |
| if (!this.isRender && !isExistRequestCache) { | |
| this.requestCache.clear(); | |
| } | |
| const shouldClearCache = !this.clearCacheIgnoreList.some( | |
| (req) => | |
| req.method === config.method && | |
| (!req.uri || new RegExp(req.uri).test(config.url)) | |
| ); | |
| if (shouldClearCache) { | |
| this.requestCache.clear(); | |
| } else { | |
| this.requestCache.set(key, promise); | |
| } |
673c1cf to
b9d4eb7
Compare
refs NEXT_BUILDER-1908
b9d4eb7 to
f7a6d41
Compare

refs NEXT_BUILDER-1908
依赖检查
组件之间的依赖声明,是微服务组件架构下的重要信息,请确保其正确性。
请勾选以下两组选项其中之一:
或者:
提交信息检查
Git 提交信息将决定包的版本发布及自动生成的 CHANGELOG,请检查工作内容与提交信息是否相符,并在以下每组选项中都依次确认。
破坏性变更:
feat作为提交类型。BREAKING CHANGE: 你的变更说明。新特性:
feat作为提交类型。问题修复:
fix作为提交类型。杂项工作:
即所有对下游使用者无任何影响、且没有必要显示在 CHANGELOG 中的改动,例如修改注释、测试用例、开发文档等:
chore,docs,test等作为提交类型。