Skip to content

A quick and easy redis cache for intensive functions

Notifications You must be signed in to change notification settings

widgetbot-io/cachified

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cachified - A plug and play NestJS Redis powered cache.

Downloads npm bundle size Version License

Cachified is an easy to use, redis-powered caching library that allows you to quickly cache your functions using TypeScript decorators.
It allows you to cache functions with a one line addition to your code.

A simple but descriptive example on how to use Cachified can be found in the example folder.


Initializing Cachified

example.service.ts

import { Injectable } from '@nestjs/common';
import { Cachified } from '@venix/cachified';

@Injectable()
export class ExampleService {
    @Cachified()
    cachedMethod() {
        return "Hey from cached method"       
    }
}

app.module.ts Using Redis client data

import { Module } from '@nestjs/common';
import { CachifiedModule } from '@venix/cachified';
import { ExampleService } from './example.service.ts';

const isProduction = process.env.NODE_ENV === 'production';  

@Module({
    imports: [
        CachifiedModule.forRoot({
            enabled: isProduction,
            client: {
                host: '127.0.0.1',
                port: 6379,
                db: 0,
                keyPrefix: 'project:'
            }
        })
    ],
    providers: [
        ExampleService
    ]
})
export class ApplicationModule {}

app.module.ts Using pre-defiend redis client

import { Module } from '@nestjs/common';
import { CachifiedModule } from '@venix/cachified';
import * as IORedis from 'ioredis';
import { ExampleService } from './example.service.ts';

const isProduction = process.env.NODE_ENV === 'production';  

const redisClient = new IORedis({
    host: '127.0.0.1',
    port: 6379,
    db: 0,
    keyPrefix: 'project:'
});

@Module({
    imports: [
        CachifiedModule.forRoot({
            enabled: isProduction,
            client: redisClient
        })
    ],
    providers: [
        ExampleService
    ]
})
export class ApplicationModule {}

If you have any feature requests you would like to be implemented please open an issue.

About

A quick and easy redis cache for intensive functions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published