Skip to content

Another cache provider for AdonisJs. Supports Object, File, Db and Redis cache. With cache dependencies!

License

Notifications You must be signed in to change notification settings

alexdonh/adonis-cache

Repository files navigation

Adonis Cache

Another cache provider for AdonisJs. Supports Object, File, Db and Redis data store. It also supports cache dependencies.

Installation

$ adonis install git+https://github.com/alexdonh/adonis-cache.git --as=adonis-cache

Install optional dependencies to use. For example, install

$ npm i fs-extra microtime moment proper-lockfile

to use file store caching.

Setup

  1. Register cache providers in start/app.js file.
const providers = [
  ...
  '@adonisjs/lucid/providers/LucidProvider',
  'adonis-cache/providers/CacheProvider'
]

const aceProviders = [
  ...
  '@adonisjs/lucid/providers/MigrationsProvider',
  'adonis-cache/providers/CommandsProvider'
]
  1. Run the migrations if using db store cache. See https://adonisjs.com/docs/4.1/migrations
$ adonis migration:run

Usage

const Cache = use('Adonis/Addons/Cache') // or alias: use('Cache')

// set cache
await Cache.set('key', 'This is a value', 60 * 60 * 24) // 24 hours

// get cache
await Cache.get('key')

// add cache, error if key exists
await Cache.add('key', something)

// check if cache exists
await Cache.exists('key')

// delete cache
await Cache.delete('key')

// flush all caches
await Cache.flush()

// use another cache store 'key', 'db', 'object', 'redis', or your own custom store
await Cache.store('file').get('key')

Register a custom cache store

Updating...

Credits

Support

Having trouble? Open an issue!

License

The MIT License (MIT). See License File for more information.

About

Another cache provider for AdonisJs. Supports Object, File, Db and Redis cache. With cache dependencies!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published