Registry / devops / next-cool-cache

next-cool-cache

JSON →
library0.3.1jsnpmunverified

Type-safe cache tag management for Next.js 16+. Version 0.3.1. Next-cool-cache wraps Next.js 16's cacheTag, revalidateTag, and updateTag primitives with a typed schema, preventing silent typos and scope mismatches. It enforces consistent tag naming via autocomplete and compile-time checks. Unlike manual string tags, it supports multi-scope caching (admin vs public) and generates hierarchical tag arrays for granular invalidation. Requires Next.js >=16.0.0. Ships TypeScript types. Lightweight with zero runtime dependencies beyond Next.js.

npm install next-cool-cache
INSTALL
IMPORT
SIG · NEXT-COOL-CACHE
N
next-cool-cache
devopsjavascriptv0.3.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createCache
import { createCache } from 'next-cool-cache'
import createCache from 'next-cool-cache'
Named export, not default. ESM only; no CJS support.
InferCacheTypes
import { InferCacheTypes } from 'next-cool-cache'
import { InferCacheType } from 'next-cool-cache'
Utility type to extract the resulting tag structure from createCache for advanced typing.
CacheInstance
import type { CacheInstance } from 'next-cool-cache'
import { CacheInstance } from 'next-cool-cache'
Type export for annotating variables; use type import to avoid runtime overhead.

How to define a typed cache schema with scopes and use cacheTag in a Next.js server component.

// lib/cache.ts import { createCache } from 'next-cool-cache'; const schema = { users: { list: {}, byId: { _params: ['id'] as const }, }, blog: { posts: { list: {}, byId: { _params: ['id'] as const }, byAuthor: { _params: ['authorId'] as const }, }, }, } as const; const scopes = ['admin', 'public', 'user'] as const; const cache = createCache(schema, scopes); export default cache; // app/posts/[id]/page.tsx import cache from '@/lib/cache'; async function getPost(id: string) { 'use cache: remote'; cache.public.blog.posts.byId.cacheTag({ id }); const post = await db.posts.findById(id); return post; } export default async function PostPage({ params }: { params: { id: string } }) { const post = await getPost(params.id); return <div>{post.title}</div>; }
Debug
Known issues
breakingRequires Next.js >=16.0.0 with React 19 and use cache: remote directive. Not compatible with Next.js <16.
fix
Upgrade Next.js to v16; ensure 'use cache: remote' is used in cached functions.
affects: >=0.0.0
gotchaThe schema object must be created with 'as const' for full type inference. Omitting 'as const' results in string literal types being widened, losing type safety.
fix
Add 'as const' after the schema definition.
affects: >=0.0.0
gotchaParameters in _params must be specified in the order they appear in the tag path. Mismatching order leads to incorrect tag generation.
fix
Ensure parameters are listed in the same order as they are passed to cacheTag/revalidateTag.
affects: >=0.0.0
deprecatedFuture versions may rename cacheTag, revalidateTag, and updateTag to more descriptive names. Listen for deprecation warnings.
fix
Stay updated with changelog; no immediate action required.
affects: >=0.3.0
Errors
Common errors & fixes
TypeError: (0 , next_cool_cache__WEBPACK_IMPORTED_MODULE_0__.createCache) is not a function
Using default import instead of named import.
fix
Change 'import createCache from "next-cool-cache"' to 'import { createCache } from "next-cool-cache"'.
Property 'admin' does not exist on type '...'. Did you mean 'public'?
Scope name typo or scope not defined in the scopes array.
fix
Check the scopes array in createCache call. Ensure the scope name used matches exactly.
Argument of type 'string' is not assignable to parameter of type 'never'.
Schema node was defined with no _params, but an argument was passed to cacheTag/revalidateTag.
fix
Remove the argument or add _params to the schema node.
Module '"next-cool-cache"' has no exported member 'createCache'.
Project is using CommonJS (require) or outdated module resolution.
fix
Ensure TypeScript config has 'moduleResolution: "bundler"' or 'node16'; the package is ESM-only.
Upgrade
Version history
0.3.1latest on npm
Audit
Dependencies
nextrequiredPeer dependency; requires Next.js >=16.0.0 for cache primitives.
Agent activity
2 hits · last 30 days
node
2
Resources
next-cool-cache — npm install next-cool-cache · libregistry