Registry / devops / adonis5-cache

adonis5-cache

JSON →
library1.3.1jsnpmunverified

A cache provider for AdonisJS 5 supporting multiple storage backends: in-memory, Redis, and Memcached. Version 1.3.1 (latest) is stable with moderate release cadence. It offers a unified CacheManager API with custom storage support, cache tags, TTL control, events, and fallback. Differentiators include first-class AdonisJS integration via IoC container, synchronous in-memory store, and extensibility for custom storage drivers. Requires peer dependencies for Redis and Memcached backends. Ships TypeScript types.

npm install adonis5-cache
INSTALL
IMPORT
SIG · ADONIS5-CACHE
A
adonis5-cache
devopsjavascriptv1.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.

Cache
import Cache from '@ioc:Adonis/Addons/Adonis5-Cache'
import Cache from 'adonis5-cache'
AdonisJS uses IoC container paths; direct import from npm package will fail.
CacheManager
import Cache from '@ioc:Adonis/Addons/Adonis5-Cache'
import { CacheManager } from 'adonis5-cache'
CacheManager is exported as default via Cache; named export not available.
CacheStorageContract
import { CacheStorageContract } from '@ioc:Adonis/Addons/Adonis5-Cache'
import { CacheStorageContract } from 'adonis5-cache'
Type-only import for implementing custom storages.
CacheContextContract
import { CacheContextContract } from '@ioc:Adonis/Addons/Adonis5-Cache'
import CacheContextContract from 'adonis5-cache'
Named type import for context in custom storage methods.

Installation, basic in-memory caching with get/put, and custom storage registration.

// 1. Install and invoke provider // npm i --save adonis5-cache // node ace invoke adonis5-cache // 2. Configure config/cache.ts { currentCacheStorage: 'memory', enabledCacheStorages: ['memory'] } // 3. Use in service import Cache from '@ioc:Adonis/Addons/Adonis5-Cache' export default class UserService { public async getUser(id: number) { const cached = await Cache.get<{ name: string }>(`user:${id}`) if (cached) { return cached } const user = { name: 'John' } // fetch from DB await Cache.put(`user:${id}`, 60, user) return user } } // 4. Register custom storage (optional) import { CacheStorageContract } from '@ioc:Adonis/Addons/Adonis5-Cache' class MyStorage implements CacheStorageContract { get<T>(context: any, key: string): Promise<T | null> { return null } getMany<T>(context: any, keys: string[]): Promise<(T | null)[]> { return [] } put(context: any, key: string, value: any, ttl: number): void {} putMany(context: any, dict: Record<string, any>, ttl: number): void {} } Cache.registerStorage('my', new MyStorage())
Debug
Known issues
gotchaCache.put signature: key, ttl, value (not key, value, ttl). Mismatch causes unexpected behavior.
fix
Always use Cache.put(key, ttl, value) or check documentation for correct order.
affects: >=1.0.0
gotchaIoC path '@ioc:Adonis/Addons/Adonis5-Cache' is required; direct require or import from package name fails silently.
fix
Use the exact IoC path in all imports.
affects: >=1.0.0
breakingBreaking change in v1.3.0: CacheManager renamed to Cache, and import path changed from '@ioc:Adonis/Addons/AdonisCache'.
fix
Update import to '@ioc:Adonis/Addons/Adonis5-Cache' and use Cache instead of CacheManager.
affects: <1.3.0
deprecatedCache.registerStorage is deprecated in favor of config-driven storage registration in config/cache.ts.
fix
Move custom storage registration to config/cache.ts under the 'storages' key.
affects: >=1.3.0
Errors
Common errors & fixes
Cannot find module '@ioc:Adonis/Addons/Adonis5-Cache'
Provider not invoked or not registered in .adonisrc.json.
fix
Run 'node ace invoke adonis5-cache' to regenerate the IoC mappings.
TypeError: Cache.get is not a function
Using Named export instead of default import.
fix
Use 'import Cache from ...' (default) not 'import { Cache } from ...'.
Error: EACCES: permission denied, open '/path/to/node_modules/adonis5-cache/...'
Filesystem permission issue during invoke or compilation.
fix
Run commands with appropriate permissions or as non-root user.
Upgrade
Version history
1.3.1latest on npm
Audit
Dependencies
@adonisjs/eventsrequiredProvides cache event dispatching (e.g., cache:miss, cache:hit)
@adonisjs/redisoptionalRequired for Redis cache storage backend
adonis5-memcached-clientoptionalRequired for Memcached cache storage backend
Agent activity
44 hits · last 30 days
node
36
OpenAI (training)
1
Resources
adonis5-cache — npm install adonis5-cache · libregistry