npm package: @lakutata-component/cacher
Description: Lakutata Cacher Component
Author: alex.ma
Latest version: 1.0.15

<div style="text-align:center">
	<img src="https://gitee.com/nnxr/lakutata-component-cacher/raw/master/assets/lakutata-banner.png" />
</div>

[![NPM Version](https://img.shields.io/npm/v/@lakutata-component/cacher?color=informational&style=flat-square)](https://npmjs.org/package/@lakutata-component/cacher)
[![NODE Version](https://img.shields.io/node/v/@lakutata-component/cacher?color=informational&style=flat-square)](https://npmjs.org/package/@lakutata-component/cacher)
[![Known Vulnerabilities](https://snyk.io/test/npm/@lakutata-component/cacher/badge.svg?style=flat-square)](https://snyk.io/test/npm/@lakutata-component/cacher)
[![NPM Download](https://img.shields.io/npm/dm/@lakutata-component/cacher?style=flat-square)](https://npmjs.org/package/@lakutata-component/cacher)

## Features

- Memory Cache
- File System Cache
- Redis Cache
- Memcached Cache

## Quickstart

```typescript
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](https://gitee.com/nnxr/lakutata-component-cacher/issues) for
bug reports or suggestions first.

## License

[MIT](LICENSE)