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

@hirotoshioi/query-cache

v0.0.2

Published

Simple query cache

Readme

query-cache

query-cache is a lightweight library that provides simple yet powerful cache management.
Inspired by the tanstack query, it offers a flexible and straightforward way to handle caching.

Features

  • High-level and intuitive interface
    Manage data fetching with just a cache key and a fetch function.

    const data = await query.cache({ queryKey: ['key'], queryFn: async () => fetchData() });
  • Zero dependencies and lightweight
    Built with no external dependencies, making it highly performant and lightweight.

  • Compatible with both browser and server environments
    Designed to work seamlessly in both Node.js and browser contexts.

  • TypeScript support for type safety
    Fully typed API to ensure safe and efficient development.

  • Flexible cache management
    Easily configure expiration times and stale data behavior.

    await query.cache({ queryKey: ['key'], queryFn: fetchData, staleTime: 3000 });

Use Cases

  • Caching API responses
    Reduce network load and enable faster data retrieval.
  • Unified data fetching management
    Avoid duplicate fetches and streamline data handling.
  • Efficient data storage for browser and server
    Ideal for temporary data storage and cache management.

Installation

Install using one of the following commands:

npm install query-cache
# or
yarn add query-cache
# or
pnpm add query-cache

Quick Start

Here’s a basic example of how to use query-cache:

Creating a Simple Cache

import { QueryCache } from 'query-cache';

// Create a QueryCache instance
const query = new QueryCache();

// Fetch or retrieve cached data
const data = await query.cache({
  queryKey: ['example-key'], // Cache key
  queryFn: async () => {
    // Your data-fetching logic
    return 'Hello, query-cache!';
  },
});

console.log(data); // 'Hello, query-cache!'

Invalidating and Refetching Cache

You can invalidate cached data and refetch it if needed.

const query = new QueryCache();

// Fetch and cache data
await query.cache({
  queryKey: ['invalidate-example'],
  queryFn: async () => 'First Fetch',
});

// Invalidate cache
await query.invalidateCache({
  queryKey: ['invalidate-example'],
  refetch: true, // Refetch after invalidation
});

Tests

This project includes comprehensive tests to ensure reliability.

npm run test

Contributing

query-cache is open-source, and contributions are welcome! Please follow these guidelines when submitting a pull request:

  1. Follow the coding style (Prettier, ESLint).
  2. Add necessary test cases.

License

MIT License © Hiroto Shioi