npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@alicloud/fetcher-interceptor-cache-local

v1.4.9

Published

@alicloud/fetcher 请求拦截 - 缓存

Downloads

298

Readme

@alicloud/fetcher-interceptor-cache-local

@alicloud/fetcher 的本地缓存拦截器

发送请求的时候判断时候已存在缓存数据,如果存在则直接返回;如果存在正在发送的相同请求,也直接返回一个 promise(会被正在发送的请求 resolve 或 reject)。

它主要是请求拦截器,但也会拦截响应(为了获取数据),所以顺序上需要放在对响应数据提取的拦截器之后。

新增 config

interface ICacheLocalOptions {
  /**
   * 默认用 FetcherConfig._id,也可以自己指定(不推荐自己指定)
   */
  key?: string;
  /**
   * 本地缓存的生存时间(单位 ms),一旦超过会重新请求,一般建议不小于 10000,即 10s
   * 如果 ttl > 0,但已有的缓存是无生存时间的,则一定会请求
   */
  ttl?: number;
  /**
   * 如果已经有本地缓存,且未失效,指定此参数将重置缓存且重新请求
   * 注意:连续调用此类接口没有意义,跟不设 cacheLocal 一样,建议在修改数据后重新获取数据时
   */
  overwrite?: boolean;
}

interface IFetcherConfigExtra {
  /**
   * 是否做本地缓存,必须手动指定
   */
  cacheLocal?: null | boolean | ICacheLocalOptions;
  /**
   * 通常执行了某数据的「写」操作后(增、删、改)需要对其已有的本地缓存进行清理,可以在这些写操作中使用此参数,会
   * 在接口执行成功后,将缓存中 key 值带有 cacheLocalRemove 指定串的进行移除
   * 
   * 注意可能会误伤友军(不会造成问题),所以,尽可能使用常量或者 URL 本身(因为默认的 key 中是带 URL 的)
   */
  cacheLocalRemove?: string;
}