Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@appolo/cache

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@appolo/cache

appolo cache module

  • 0.0.34
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
167
increased by10.6%
Maintainers
1
Weekly downloads
 
Created
Source

Cache module for appolo.

Cache methods results using appolo-cache​ with optional redis store

Installation

npm i @appolo/cache

Options

keyDescriptionTypeDefault
idcacheProvider injector idstringcacheProvider
connectionredis connection stringstring``
memorytrue to use memory storebooleantrue
dbtrue to use redis storebooleanfalse
maxSizemax memory store itemsnumber1000
keyPrefixredis prefix keystringc

all option are optional and will be added as defaults to cache options in config/modules/all.ts

import {CacheModule} from '@appolo/cache';

export = async function (app: App) {
    await app.module(new CacheModule({maxSize:100}));

   // or with redis store
   await app.module(new CacheModule({db:true,connection:"redis://redis-connection-string"}));

}

Cache Options

keyDescriptionTypeDefault
idcustom cache idstringclassName_methodName
maxSizemax cache sizenumber1000
maxAgeset maximum age in ms of all cache itemsnumberunlimited
cloneclone the cache resultbooleanfalse
intervalset cache refresh interval in msnumberundefined
resolverfunction to get the cache key by default the first argument will be used as the cache key.functionundefined
multiif no resolver defined use all the arguments as key else use the first argument as keybooleanfalse
peekuse peek method instead of getbooleanfalse
refreshrefresh cache on half maxAge expirebooleanfalse
keyPrefixredis prefix keystringc
memorytrue to use memory storebooleantrue
dbtrue to use redis storebooleanfalse
dbMaxAgeset maximum age in ms of all cache items in db if not defined maxAge will be usednumberunlimited

Usage

import { cache,define } from 'appolo';

@define()
export class SomeClass {
    private counter = 0;

    @cache()
    method() {
       return ++this.counter
    }

    // will be refreshed every 5 sec
    @cache({interval:5000})
    async method2(key:string) {
        let result = await doSomeThingAsync(key)
        return result;
    }

     // will try to get items from memroy with expire
     // of 1 minute then from redis with expire of one hour
    @cache({db:true,maxAge:60*1000,:dbMaxAge:60*1000*60})
        async method2(key:string) {
            let result = await doSomeThingAsync(key)
            return result;
        }
}

CacheProvider

createCache(options: ICacheOptions, valueFn: Function, scope?: any)

create new cache wrapper

  • options - cache options
  • valueFn - value function will be called to get the value
  • scope - scope of the value function

getCacheById(id:string):Cache

return cache wrapper by id

Cache

cache wrapper instance

get<T>(...args: any[]): Promise<T> | T

get value from cache if not found the value fn will be called

get cache

return appolo-cache​ instance

Keywords

FAQs

Package last updated on 04 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc