npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@appolo/cache

v8.0.3

Published

appolo cache module

Downloads

776

Readme

Cache module for appolo.

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

Installation

npm i @appolo/cache

Options

| key | Description | Type | Default | --- | --- | --- | --- | | id | cacheProvider injector id | string| cacheProvider| | connection | redis connection string | string| ``| | memory | true to use memory store | boolean| true| | db | true to use redis store | boolean| false| | maxSize | max memory store items | number| 1000| | keyPrefix | redis prefix key | string| c|

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

| key | Description | Type | Default | --- | --- | --- | --- | | id | custom cache id | string| className_methodName| | maxSize | max cache size | number| 1000| | maxAge | set maximum age in ms of all cache items | number | unlimited | | clone | clone the cache result | boolean | false | | interval | set cache refresh interval in ms | number | undefined | | resolver | function to get the cache key by default the first argument will be used as the cache key. | function | undefined | | multi | if no resolver defined use all the arguments as key else use the first argument as key | boolean | false | | peek | use peek method instead of get | boolean | false | | refresh | refresh cache on half maxAge expire | boolean | false | | keyPrefix | redis prefix key | string| c| | memory | true to use memory store | boolean| true| | db | true to use redis store | boolean| false| | dbMaxAge | set maximum age in ms of all cache items in db if not defined maxAge will be used | number | unlimited |

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