Ant-design-pro: request 模块中的 cacheSave 方法存在的意义到底是什么?

Created on 4 Oct 2018  ·  7Comments  ·  Source: ant-design/ant-design-pro

刚刚在开发过程中,我发现 ant design pro 在默认 request 模块里面加了一个 cacheSave 方法,用来将同样结构(例如参数没有发生变化的 post 请求)的请求的结果进行缓存。这直接导致了我开发的页面出现了数据更新后刷新请求不到服务器的问题。

这样对所有请求进行结果缓存的逻辑处理窃以为是很有问题的,需要让两次请求的不同能够体现出来的场景是普遍存在的。请问你们默认这样做的思考是怎样的呢?

🙏help wanted

Most helpful comment

@chenshuai2144 似乎并不是的。

export default function request(
    url,
    options = {
        expirys: isAntdPro(),
    }
)

这是目前的 request 方法的定义。如果我使用了 post 请求,覆盖了 options 这个参数的话:

export async function updateA(params={}) {
    return request('/api/a/update', {
        method: 'POST',
        body: params,
    });
}

这里的 isAntdPro 就不起作用了。我昨晚测试过程中,就是在本地调试时,遇到了同样 fingerprint 的 post 请求走缓存这一边的逻辑了。

All 7 comments

同时提出该 issue,希望遇到类似问题的朋友能够查找到。

pro 的请求都是相同的,mock 数据并不会频繁修改,所以使用了这个。
这个类似 pwa,是一个小特性。默认应该关掉它

@chenshuai2144 在代码里面没有注释提到这一点,请问可以提交 pr 加注释标记吗?

目前的做法会导致使用者在正式开发过程中使用到该部分代码。

export function isAntdPro() {
  return window.location.hostname === 'preview.pro.ant.design';
}

用了这个方法,本地调试都不会用

@chenshuai2144 似乎并不是的。

export default function request(
    url,
    options = {
        expirys: isAntdPro(),
    }
)

这是目前的 request 方法的定义。如果我使用了 post 请求,覆盖了 options 这个参数的话:

export async function updateA(params={}) {
    return request('/api/a/update', {
        method: 'POST',
        body: params,
    });
}

这里的 isAntdPro 就不起作用了。我昨晚测试过程中,就是在本地调试时,遇到了同样 fingerprint 的 post 请求走缓存这一边的逻辑了。

你可以提个 pr 修掉这个 bug。

image

把这块代码注释掉jiu'hao'le就好了

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wuyongdec picture wuyongdec  ·  3Comments

RichardStark picture RichardStark  ·  3Comments

yadongxie150 picture yadongxie150  ·  3Comments

cheung1111 picture cheung1111  ·  3Comments

Jerry-goodboy picture Jerry-goodboy  ·  3Comments