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

myhttpcache

v1.0.1

Published

前端请求缓存方案 http cache request cache

Downloads

2

Readme

MyHttpCache

基于 map 设计的前端接口请求缓存方案

特点

  1. 基于 map 实现缓存池,无法离线缓存,窗口关闭和浏览器刷新等均会到导致缓存失效,下次访问数据时,将向服务器发起请求。
  2. 可设置缓存时间,超时后再次访问数据,将向服务器发起请求
  3. 同一 API 接口,可根据参数不同而设置不同的缓存对象。
  4. 可调用 delete 方法手动清除缓存

使用场景

  1. token 缓存与更新
  2. 组织结构等变动比较下,但使用频繁的数据
  3. 其它

静态方法

| 方法 | 方法说明 | 参数说明 | | --------------------- | ------------------------------------------------------- | ---------------------------------------------------------------------- | | set(key,data,timeout) | 设置缓存 | key:map 主键;data:写入的缓存数据;timeout:数据缓存时间/秒(默认 3600 秒) | | get(key) | 从缓存池中获取数据,若数据不存在或者缓存过期则返回 null | key:map 主键 | | delete(key) | 从缓存池中删除目标数据 | key:map 主键 |

案例

import MyHttpCache from "MyHttpCache"

async function getData {
  let url = `xxx/api/getData`;
  let data = MyHttpCache.get({ url });
  if (!data) {
    const response = await request({url});
    // 设置缓存有效时间为20min
    MyHttpCache.set({ url }, response,1200);
    data = response;
  }
  return data;
}