1.0.15 • Published 2 years ago

@lakutata-component/cacher v1.0.15

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

NPM Version NODE Version Known Vulnerabilities NPM Download

Features

  • Memory Cache
  • File System Cache
  • Redis Cache
  • Memcached Cache

Quickstart

import {createApp} from '@lakutata/core'
import {CacherComponent, CacheOptions} from '@lakutata-component/cacher'

createApp({
    id: 'cache.test.app',
    name: 'cache-test',
    components: {
        memoryCache: {
            class: CacherComponent,
            options: {
                type: 'memory',
                ttl: 5
            } as CacheOptions
        },
        redisCache: {
            class: CacherComponent,
            options: {
                type: 'redis',
                host: 'localhost',
                ttl: 5
            } as CacheOptions
        },
        fsCache: {
            class: CacherComponent,
            options: {
                type: 'fs',
                ttl: 5
            } as CacheOptions
        },
        memcachedCache: {
            class: CacherComponent,
            options: {
                type: 'memcached',
                hosts: 'localhost',
                ttl: 5
            } as CacheOptions
        }
    }
}).then(async app => {
    const memoryCacheComponent: CacherComponent = app.Components.get<CacherComponent>('memoryCache')
    const redisCacheComponent: CacherComponent = app.Components.get<CacherComponent>('redisCache')
    const fsCacheComponent: CacherComponent = app.Components.get<CacherComponent>('fsCache')
    const memcachedCacheComponent: CacherComponent = app.Components.get<CacherComponent>('memcachedCache')
    await memoryCacheComponent.set('cacheKey', {testMsg: 'This is memoryCache'})
    await redisCacheComponent.set('cacheKey', {testMsg: 'This is redisCache'})
    await fsCacheComponent.set('cacheKey', {testMsg: 'This is fsCache'})
    await memcachedCacheComponent.set('cacheKey', {testMsg: 'This is memcachedCache'})
    setTimeout(async () => {
        app.Logger.info(await memoryCacheComponent.get('cacheKey'))
        app.Logger.info(await redisCacheComponent.get('cacheKey'))
        app.Logger.info(await fsCacheComponent.get('cacheKey'))
        app.Logger.info(await memcachedCacheComponent.get('cacheKey'))
    }, 1000)
}).catch(e => {
    console.error(e)
    process.exit(1)
})

@lakutata/core required.

How to Contribute

Please let us know how can we help. Do check out issues for bug reports or suggestions first.

License

MIT

1.0.15

2 years ago

1.0.14

2 years ago

1.0.10

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

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

3 years ago

1.0.0

3 years ago