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

@oomol-lab/resource-cache

v0.1.5

Published

Persistent and session-scoped resource caching with freshness tracking and conditional revalidation.

Readme

@oomol-lab/resource-cache

Docs Build Status npm-version Coverage Status minified-size

Cache complete responses in IndexedDB or sessionStorage, with expiration and ETag revalidation.

Install

npm add @oomol-lab/resource-cache

Usage

import { createPersistentCache, type CacheOptions } from '@oomol-lab/resource-cache'

type Item = { id: string; name: string }
type Query = { locale: string }

function decodeItems(value: unknown): Item[] {
  if (!Array.isArray(value) || !value.every(item =>
    item !== null && typeof item === 'object' &&
    typeof item.id === 'string' && typeof item.name === 'string'
  )) {
    throw new TypeError('Invalid items response')
  }
  return value
}

const cacheOptions: CacheOptions<Item[], Query> = {
  namespace: 'production:items',
  schemaVersion: 1,
  maxAge: 5 * 60_000,
  key: ({ locale }) => locale,
  decode: decodeItems,
  async load({ locale }, { etag, signal }) {
    const response = await fetch(`/api/items?locale=${encodeURIComponent(locale)}`, {
      headers: etag === null ? {} : { 'If-None-Match': etag },
      signal,
    })
    if (response.status === 304) {
      return { modified: false, etag: response.headers.get('ETag') ?? undefined }
    }
    if (!response.ok) throw new Error(`Loading items failed: ${response.status}`)
    return {
      modified: true,
      data: decodeItems(await response.json()),
      etag: response.headers.get('ETag'),
    }
  },
}

const items = createPersistentCache(cacheOptions)
const data = await items.get({ locale: 'en' })

Use load to send requests and validate network responses. Use decode to restore stored data. Treat returned data as read-only.

| load result | Meaning | | --- | --- | | { modified: true, data, etag } | Replace the complete response and ETag. Use null when no ETag is available. | | { modified: false, etag? } | Reuse the response associated with the supplied ETag. Omit etag to retain it; use null to clear it. |

Options

| Option | Value | | --- | --- | | namespace | Nonblank resource and environment name. | | schemaVersion | Positive safe integer. Increment for incompatible response or decoding changes. | | maxAge | Finite nonnegative milliseconds. Zero requires validation on every access. | | key(query) | Stable string identifying the complete response. | | decode(value) | Synchronous function that restores stored data; throw to reject an unusable record. | | load(query, { etag, signal }) | Async function returning a complete response or an unmodified result. | | sessionId | Nonblank, non-secret login identifier, required by createSessionCache. |

Choose different namespaces for different data environments. Include locale, user, team, permissions, and filters in the key when they affect the response. Caches sharing an identity must use compatible response and decoding contracts. Invalid factory options throw TypeError.

IndexedDB data must support structured cloning. Session data must survive JSON serialization and restoration through decode.

Read and refresh

| Call | Result | | --- | --- | | get(query) | Return fresh data or await loading. Loading errors reject the call. | | get(query, { revalidate: true }) | Require a new validation, even when cached data is fresh. | | get(query, { signal }) | Cancel this caller's wait with AbortError; shared loading continues. | | peek(query) | Read without loading. Return a snapshot, possibly stale, or undefined. |

maxAge controls how long a successful response or validation can be reused. An unmodified result retains the cached data and refreshes its validation time. Returning modified: false without cached data rejects as a protocol error.

Concurrent loading of the same key is shared within an instance. A forced call made during an active request waits for a subsequent validation. For stale UI display, read with peek, then request fresh data with get.

Failed storage reads fall back to loading. Successful loads remain available in memory when saving fails.

Invalidate and clear

| Call | Effect | | --- | --- | | invalidate(query) | Mark stale while retaining data and ETag. | | remove(query) | Delete data and ETag. | | clear() | Clear the current namespace, schemaVersion, and sessionId scope. | | dispose() | Close the instance. Keep IndexedDB data; delete session data for this namespace/sessionId across all schema versions. |

These calls reject affected in-flight get and peek calls with AbortError. Cleanup errors propagate to the caller; failed deletion may leave stored data behind. Retry dispose() if session cleanup fails. Other methods reject after disposal.

Coordinate invalidation and logout across every affected instance and page. Other instances can retain fresh memory or save their own request results after a cleanup.

Login sessions

import { createSessionCache } from '@oomol-lab/resource-cache'

const sessionItems = createSessionCache({ ...cacheOptions, sessionId: loginSessionId })

// On logout:
await sessionItems.dispose()

Supply loginSessionId from the application's login state. Keep it stable across page refreshes within a login and choose a new identifier for each new login. Never use an access token. Change the cache scope or invalidate related caches when team or permission scope changes.

OOMOL response types

import type {
  ProvidersResponse,
  ActionsResponse,
  AppCatalogResponse,
  AppMarketingResponse,
  ConnectionsResponse,
} from '@oomol-lab/resource-cache/oomol'

| Type | Successful response | | --- | --- | | ProvidersResponse | /v1/providers, including top-level meta and sprite metadata. | | ActionsResponse | /v1/actions?service=…, including the complete service action catalog. | | AppCatalogResponse | /public/v1/apps, including featured actions, availability, catalog aggregates, and sprite metadata. | | AppMarketingResponse | /public/v1/apps/{service}, including website marketing content, optional landing content, capabilities, and locale metadata. | | ConnectionsResponse | /v1/connections, including connection app views and summary metadata. |

Validate these responses in load and decode.

The OOMOL entry exports separate configuration types, ProvidersCacheOptions, ActionsCacheOptions, AppCatalogCacheOptions, and AppMarketingCacheOptions. These factories serve data shared across accounts, teams and flows. They use fixed namespaces and include environment and locale (and, for Actions and App Marketing, service) in the cache identity, so callers do not need to construct namespace or key strings. environment defaults to production and can be set to values such as staging when the host serves a separate deployment. A request may still require an access token. Keep that token in the Providers or Actions request layer inside load; App Catalog and App Marketing are public and do not require credentials. Credentials must not be used as a cache key, namespace, or environment value.

Use getProvidersCache, getActionsCache, getAppCatalogCache, and getAppMarketingCache. They return the shared cache for an environment, locale and schema version. The first call fixes load, decode, and maxAge for that identity; provide a stable load function that reads the current request credentials. The singleton registry is shared across package copies in the same JavaScript runtime.

import { getAppCatalogCache } from '@oomol-lab/resource-cache/oomol'

const apps = getAppCatalogCache({
  environment: 'production',
  locale: 'zh-CN',
  schemaVersion: 1,
  maxAge: 10 * 60_000,
  decode: decodeAppCatalog,
  load: ({ locale }, validation) => api.getPublicApps({ locale, ...validation }),
})

const response = await apps.get()

An Actions cache accepts the service as the operation query, so one shared instance can serve multiple services:

import { getActionsCache } from '@oomol-lab/resource-cache/oomol'

const actions = getActionsCache({
  locale: 'zh-CN',
  schemaVersion: 1,
  maxAge: 10 * 60_000,
  decode: decodeActions,
  load: ({ locale, service }, validation) => api.getActions({ locale, service, ...validation }),
})

const gmail = await actions.get('gmail')
const calendar = await actions.get('calendar')

App Marketing also accepts a service per operation and stores the complete website marketing response in IndexedDB:

import { getAppMarketingCache } from '@oomol-lab/resource-cache/oomol'

const marketing = getAppMarketingCache({
  locale: 'zh-CN',
  schemaVersion: 1,
  maxAge: 10 * 60_000,
  decode: decodeAppMarketing,
  async load({ locale, service }, { etag, signal }) {
    const response = await fetch(
      `https://connector.oomol.com/public/v1/apps/${encodeURIComponent(service)}?locale=${encodeURIComponent(locale)}`,
      { headers: etag === null ? {} : { 'If-None-Match': etag }, signal },
    )
    if (response.status === 304) {
      return { modified: false, etag: response.headers.get('ETag') ?? undefined }
    }
    if (!response.ok) throw new Error(`Loading app marketing failed: ${response.status}`)
    return {
      modified: true,
      data: decodeAppMarketing(await response.json()),
      etag: response.headers.get('ETag'),
    }
  },
})

const response = await marketing.get('gmail')
const content = response.data.content // May be null when no editorial content exists.

Supply your response validator as decodeAppMarketing. Send the configured locale explicitly in the request so the cache identity matches the requested language instead of relying on a changing Accept-Language header. The response retains meta.locale, meta.contentLocale, and meta.availableContentLocales to describe language fallbacks. A successful response with content: null is cached normally; failed requests reject without replacing cached data.

Connections are scoped to a login session and use sessionStorage. The required sessionId must be a stable, non-secret login identifier, never an access token. ownerId identifies the connection owner and is part of the cache identity. Call dispose() when the session ends; it removes all connection scopes for that login session.

import { getConnectionsCache } from '@oomol-lab/resource-cache/oomol'

const connections = getConnectionsCache({
  environment: 'production',
  sessionId: loginSessionId,
  ownerId: currentOwnerId,
  schemaVersion: 1,
  maxAge: 60_000,
  decode: decodeConnections,
  load: ({ ownerId }, validation) => api.getConnections({ ownerId, ...validation }),
})

const response = await connections.get()
await connections.dispose() // on logout

Use the generic cache API for account- or permission-specific endpoints that do not match the Connections response contract.

Contributing

Development checks and implementation contracts