1.0.7 • Published 2 years ago

@cyclonecode/service-cache v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Service Cache

This package adds support to cache return values from service calls in nodejs.

Install

npm install @cyclonecode/service-cache

Cache method return value

import { ServiceCache } from 'service-cache'

class MyService {
    @ServiceCache()
    // @ServiceCache({ key: 'myKey' })
    // @ServiceCache({ ttl: 60000 })
    // @ServiceCache(( key: 'myKey', ttl: 6000 })
    fetchFromApi() {
        // return response from external api.
    }
}

Cache all method return values in a class

import { ServiceCache } from 'service-cache'

@ServiceCache()
// @ServiceCache({ key: 'myKey' })
// @ServiceCache({ ttl: 60000 })
// @ServiceCache(( key: 'myKey', ttl: 6000 })
class MyService {
    fetchFromTwitter() {
        // return response from twitter api.
    }

    fetchFromInstagram() {
        // return response from instagram.
    }
}

Configuration

The package is using dotenv to access environment variables; you can change the default cache key and ttl using:

CACHE_KEY=defaultCacheKey
CACHE_TTL=5000
1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago