Registry / database / adonisjs-cache

adonisjs-cache

JSON →
library2.0.0jsnpmunverified

A cache provider for AdonisJS v5+ with file-based storage and TTL support. Current version 2.0 provides ESM-only exports and TypeScript types. Released as needed. Differentiates by being a native Laravel-style cache for AdonisJS, integrating seamlessly with the framework's IoC container. Supports cache tags and cache events.

npm install adonisjs-cache
INSTALL
IMPORT
SIG · ADONISJS-CACHE
A
adonisjs-cache
databasejavascriptv2.0.0
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.

CacheManager
import { CacheManager } from 'adonisjs-cache'
const { CacheManager } = require('adonisjs-cache')
ESM-only since v2; CommonJS require will fail. Use ES import syntax.
cache
import cache from 'adonisjs-cache/services/cache'
import cache from 'adonisjs-cache'
Default export is not the CacheManager instance; use the service export to get the pre-configured cache singleton.
CacheContract
import type { CacheContract } from 'adonisjs-cache/types'
import { CacheContract } from 'adonisjs-cache'
Type imports should come from the types subpath to avoid runtime errors in production.

Shows how to configure, import, and use CacheManager in an AdonisJS controller with TTL.

// Install: npm install adonisjs-cache // Configure: node ace configure adonisjs-cache // In a controller or service import { CacheManager } from 'adonisjs-cache' export default class PostsController { public async index({ cache }: { cache: CacheManager }) { const posts = await cache.get('posts') if (!posts) { // fetch from DB const fresh = await Post.all() await cache.set('posts', fresh, 60 * 60) // 1 hour return fresh } return posts } } // Using the cache service import cache from 'adonisjs-cache/services/cache' await cache.set('key', 'value', 300)
Debug
Known issues
breakingIn v2, the package is ESM-only. CommonJS imports will cause a runtime error.
fix
Use ES import syntax. Ensure node --experimental-specifier-resolution=node is set if needed.
affects: >=2.0.0
deprecatedThe ability to configure cache driver via config/cache.ts has been removed since v2.0.
fix
Use the new provider-based configuration via .env or environment variables. See migration guide.
affects: >=2.0.0
gotchaDefault cache store is file-based in the 'tmp' directory. Not persisted outside the server process in production.
fix
Configure a persistent store like Redis or set cache to use a non-volatile directory.
affects: >=1.0.0
breakingCache tags are not supported in v2. The getTags() and setWithTags() methods have been removed.
fix
Use scoped cache keys or custom logic to mimic tags.
affects: >=2.0.0
gotchaUsing cache.get() with a non-existent key returns null, not undefined or false.
fix
Check for null if you rely on falsy equality checks.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_MODULE_NOT_FOUND: Cannot find module 'adonisjs-cache'
CommonJS require used with an ESM-only package in v2.
fix
Change const cache = require('adonisjs-cache') to import cache from 'adonisjs-cache'
Missing required dependency: @adonisjs/core
Cache provider relies on AdonisJS IoC container but it is not installed.
fix
Ensure AdonisJS project setup with @adonisjs/core installed. Run 'npm install @adonisjs/core'.
Cannot find module 'adonisjs-cache/services/cache'
Import path incorrect due to missing extension or misconfigured module resolution.
fix
Use correct import path: 'adonisjs-cache/services/cache' without extension. Ensure TypeScript moduleResolution set to 'node'.
TypeError: cache.set is not a function
Importing the default export instead of the cache service or CacheManager instance.
fix
Use import cache from 'adonisjs-cache/services/cache'.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
@adonisjs/corerequiredRequired peer dependency to use Cache provider within AdonisJS application
@adonisjs/sessionoptionalOptional peer dependency for session-based cache
Agent activity
31 hits · last 30 days
node
26
OpenAI (training)
1
Resources
adonisjs-cache — npm install adonisjs-cache · libregistry