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 🙏

© 2026 – Pkg Stats / Ryan Hefner

abit-cache

v1.0.6

Published

React cache library from scratch

Readme

React Abit Cache 🚀

A powerful React caching library with features like optimistic updates, cache invalidation, and more.

Features

  • 🕒 Data caching
  • ♻️ Automatic revalidation on focus, reconnect, or interval
  • ⚡ Optimistic updates for mutations
  • 🧩 Suspense mode support
  • 🔍 Deep comparison for efficient updates
  • 🗑️ Cache invalidation by key or pattern matching
  • 🔄 Retry mechanism for failed requests
  • 📦 Lightweight and tree-shakable

Installation

npm install abit-cache
# or
yarn add abit-cache

Quick Start

  1. Wrap your app with CacheProvider
import { CacheProvider } from 'abit-cache';

function App() {
  return (
    <CacheProvider
      value={{
        staleTime: 1000 * 60 * 5, // 5 minutes
        isRevalidateOnFocus: true,
      }}
    >
      <YourApp />
    </CacheProvider>
  );
}
  1. Use useQuery for data fetching
import { useQuery } from 'abit-cache';

function UserProfile({ userId }) {
  const { data, error, isLoading } = useQuery(
    ['user', userId],
    async ([, id]) => {
      const response = await fetch(`/api/users/${id}`);
      return response.json();
    },
    {
      staleTime: 1000 * 30, // 30 seconds
      onSuccess: (data) => console.log('User loaded:', data),
    },
  );
  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;
}

return <div>{data.name}</div>;
  1. Use useMutation for data updates
import { useMutation } from 'abit-cache';

function UpdateProfile() {
  const { mutate, isMutating } = useMutation(
    'update-profile',
    async (variables) => {
      const response = await fetch('/api/profile', {
        method: 'POST',
        body: JSON.stringify(variables),
      });
      return response.json();
    },
    {
      optimisticData: (currentData) => ({
        ...currentData,
        ...variables,
      }),
    },
  );

  const handleSubmit = (data) => {
    mutate(data, {
      onSuccess: () => alert('Profile updated!'),
    });
  };

  return (
    <form onSubmit={handleSubmit}>
      <button type="submit" disabled={isMutating}>
        {isMutating ? 'Saving...' : 'Save'}
      </button>
    </form>
  );
}

API Reference

CacheProvider

| Prop | Type | Description | | ----- | ------------ | ----------------------------------- | | value | TCacheConfig | Configuration options for the cache |

useQuery

const {
  data,
  error,
  isLoading,
  revalidate,
  invalidate,
  invalidateMatching,
  clear,
} = useQuery<TData>(key, fetcher, options);

Parameters:

| Parameter | Type | Description | | --------- | ------------------------------- | --------------------------------------------- | | key | string | array | object | Unique key for the query | | fetcher | function | Function that returns a Promise with the data | | options | object (optional) | Configuration object |

Options:

| Option | Type | Default | Description | | ------------------------- | ---------- | -------------- | ------------------------------------ | | isEnabled | boolean | true | Whether the query should execute | | isSuspense | boolean | false | Enable Suspense mode | | staleTime | number | 0 | Time until data is considered stale | | isRevalidateIfStale | boolean | true | Auto-revalidate when stale | | isRevalidateOnFocus | boolean | false | Revalidate when window regains focus | | isRevalidateOnReconnect | boolean | false | Revalidate when network reconnects | | isKeepPreviousData | boolean | false | Keep previous data while loading | | shouldRetryOnError | boolean | true | Retry on error | | errorRetryInterval | number | 5000 | Delay between retries (ms) | | errorRetryCount | number | 3 | Max retry attempts | | dedupingInterval | number | 2000 | Dedupe simultaneous requests (ms) | | focusThrottleInterval | number | 5000 | Throttle focus revalidation (ms) | | onSuccess | function | - | Callback on successful fetch | | onError | function | - | Callback on error | | onErrorRetry | function | - | Custom error retry handler | | isDeepEqual | function | shallowEqual | Custom equality function |

useMutation

const {
  isMutating,
  error,
  data,
  mutate,
  invalidate,
  invalidateMatching,
  clear,
} = useMutation<TData, TVariables>(key, fetcher, options);

Parameters

| Parameter | Type | Description | | --------- | ------------------- | ----------------------------------------------------- | | key | string | Unique key for the mutation | | fetcher | function | Function that returns a Promise with the updated data | | options | object (optional) | Configuration object (optional) |

Options

| Option | Type | Default | Description | | ------------------- | -------------------- | ------- | ----------------------------------- | | isRevalidate | boolean | true | Revalidate after mutation | | isRollbackOnError | boolean | true | Rollback optimistic update on error | | optimisticData | Data | function | - | Data to show immediately | | onSuccess | function | - | Callback on successful mutation | | onError | function | - | Callback on error | | onSettled | function | - | Callback after mutation completes |

const { invalidateMatching } = useQuery(...);

// Delete all cache entries starting with 'user'
invalidateMatching('^user');

Suspense Mode

function UserProfile({ userId }) {
  const { data } = useQuery(['user', userId], fetchUser, { isSuspense: true });

  return <div>{data.name}</div>;
}

function App() {
  return (
    <Suspense fallback={<div>Loading user...</div>}>
      <UserProfile userId="123" />
    </Suspense>
  );
}

Global Configuration

<CacheProvider
  value={{
    staleTime: 1000 * 60 * 10, // 10 minutes
    isRevalidateOnFocus: true,
    isRevalidateOnReconnect: true,
    errorRetryCount: 5,
    onError: (err) => trackError(err),
  }}
>
  <App />
</CacheProvider>

TypeScript Support The library is fully typed with TypeScript. All hooks and types are exported:

import {
  useQuery,
  useMutation,
  CacheProvider,
  type TCacheOptions,
  type TMutateOptions,
} from 'abit-cache';

Contributing Contributions are welcome! Please open an issue or PR on GitHub.

License

MIT