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

js-caches

v1.0.0

Published

A simple cache library for js

Downloads

4

Readme

js-caches

GitHub Static Badge Coverage Status

js-caches 缓存库提供了三种高效的缓存策略:最近最少使用(LRU)、先进先出(FIFO)和最不经常使用(LFU)。它旨在帮助开发者轻松地在他们的应用程序中实现数据缓存机制,从而提高性能和响应速度。

安装

通过NPM安装

$ npm install your-cache-library-name

快速开始

import { LRUCahche, FIFOCache, LFUCache } from 'js-caches';

const cache = new LRUCahche<number, number>(3);
cache.put(1, 9);
cache.put(2, 8);
cache.put(3, 7);
cache.put(4, 6); // 超出最大缓存容量,淘汰key为1的缓存(最近最少使用)
cache.has(1) // false
cache.get(1) // null

cache.get(2); // key为2的缓存成为最近使用的缓存
cache.put(5, 10);  // 超出最大缓存容量,淘汰key为3的缓存(最近最少使用)
cache.has(3) // false
cache.get(3)) // null

缓存策略

LRU

LFU

FIFO

API

new

实例化一个缓存对象

参数

  • capacity: 最大缓存容量

返回值: 实例化后的缓存对象

get(key)

根据提供的键(key)从缓存中检索一个值。如果键存在,则返回对应的值;如果不存在,则返回null

参数

  • key: 需要检索的键,通常是一个字符串或者可以作为键的任何类型

返回值: 键对应的值,键不存在时返回null

put(key, value)

将一个值(value)与一个键(key)关联并加入到缓存中。如果缓存已经达到其配置的最大容量,则根据缓存策略(LRU、FIFO、LFU)淘汰一个现有的项目

参数

  • key: 要设置的键
  • value: 与键关联的值

返回值: 无。

has(key)

检查缓存中是否存在指定的键(key)

参数

  • key: 需要检查是否存在的键

返回值

  • true: 如果缓存中存在该键
  • false: 如果缓存中不存在该键

贡献

欢迎贡献!如果你有好的想法或者发现了bug,请通过issue或者pull request与我联系

许可证

这个项目采用 MIT许可证