Skip to content

缓存

实例缓存

通过设置 cacheSetting 参数来实现 useFetch 请求的缓存,

javascript
import { useFetch } from "fluth-vue";

const { data, execute, promise$, clearCache } = useFetch(url, {
  cacheSetting: {
    expiration: 1000 * 60 * 5;
    cacheResolve: ({url, payload}) => url + payload.id;
  }.post(payload).json();
});

提示

  • 当前缓存实现是存在内存中
  • execute命中缓存返回的是 Promise.resolve(cacheData),所以可以使用execute.then来进行后续动作
  • 命中缓存promise$不会推流

全局缓存

可以通过 clearFetchCache 来清空所有 useFetch 的缓存

javascript
import { clearFetchCache } from "fluth-vue";

clearFetchCache();