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())
Errors
Common errors & fixes
Cannot find module '@ioc:Adonis/Addons/Adonis5-Cache'
Provider not invoked or not registered in .adonisrc.json.
fixRun 'node ace invoke adonis5-cache' to regenerate the IoC mappings.
TypeError: Cache.get is not a function
Using Named export instead of default import.
fixUse '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.
fixRun commands with appropriate permissions or as non-root user.
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