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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@lrhealth/storage

v1.0.2

Published

联仁健康内部缓存隔离包

Readme

@lrhealth/storage

背景说明

公司内部多个web项目同时部署在同一台服务器的nginx下,ip和端口都是一致的,这样就会使得多个项目共用一个localStorage缓存,造成读写冲突的问题。为了解决这个问题,就必须对同域下,多项目本地缓存进行隔离。把不同项目对应的本地缓存,存储在localSforage不同的key-value里

使用范围

此包仅限于在 联仁科技(联仁健康医疗大数据科技股份有限公司)内部使用

安全风险

因为此包的数据处理对象包含token等关键信息,如果出现一些bug,会影响项目登录功能。内部出现bug时,需及时在前端web群里发布,进行实时bugfix,不断增强此包的健壮性。促进本地缓存隔离在公司内部的最佳实践

安装依赖

npm install @lrhealth/storage --save

或者

yarn add @lrhealth/storage

注意:npm 源必须是官方源,不能是淘宝镜像源

引入方式

import 
{
  getAll,
  getItem,
  setItem,
  removeItem,
  clear
} from '@lrhealth/storage' 

参数说明

| 参数名称 | 类型 | 解释 | | ------ | ------ | ------ | | prefix | string | 项目名称 | | item | string | 缓存中的键 | | data | 任意类型 | 要存入缓存的原始数据 (内部会自动进行序列化转换,不用像原始的localStorage一样,存取前后进行序列化处理)|

方法说明

声明:暴露的方法延用了浏览器原生的localStorage方法名,增加了一个getAll(prefix)方法,用于读取当前项目对应的所有本地缓存数据。相比原生的传参方式,每个方法需要多传一个项目名称prefix,加以区分;但是不需要像原生的方法一样必须做序列化转化才能存取,包内部会自动做序列化处理的。以下是具体使用说明:

  • getAll(prefix)

作用:传入 项目名称 prefix,获取当前web项目对应的所有localStorage缓存数据,
使用场景: 一般用来读取打印当前web项目对应的本地缓存localStorage中的所有数据,例: getAll('ms'),getAll('supervision')//获取ms平台和监管平台对应的本地所有存储数据

  • getItem(prefix, item)

作用:传入 项目名称 prefix,要读取的子项键名item,获取对应的value值
使用场景: 一般用来读取当前项目缓存中某一项的值
例:getItem('ms','token') ,getItem('ms','roleId')//返回token和roleId数据

  • setItem(prefix, item, data)

作用:传入 项目名称 prefix,自定义的子项键名item,和value值data,将该项数据存入本地localStorage对应的缓存空间内。
使用场景: 一般用于登录存token,例: setItem('ms','token','AE42885846848566464'), setItem('ms','userInfo',{id:34242,sex:'male',...}) 或者重置缓存里某一项的值

  • removeItem(prefix, item)

作用:传入项目名称prefix,对应的键名item,将该项数据从项目对应的缓存空间中清除
使用场景: 一般用于清除项目里某一项数据 例:
removeItem('ms','token')//清除token信息

  • clear(prefix)

作用:传入项目名称prefix,将当前web项目对应的本地缓存数据情况。
使用场景: 一般用于退出登录,清空当前项目缓存数据
clear('ms'),clear('supervision')//清除ms平台和监管平台各自的所有缓存数据

调试机制

~~包的内部内置了报错机制,当调用方法,忘记传参数或者传参有误时,会根据错误级别给出warn或者error提示,方便通过控制台的调用栈调试定位bug。调试机制需要进一步完善,遇到问题可以多提issue~~

由于报错待完善,暂时去除报错