UNPKG

@lakutata-component/cacher

Version:

Lakutata Cacher Component

60 lines (57 loc) 2.13 kB
import {createApp} from '@lakutata/core' import {CacheOptions, CacherComponent} from '../CacherComponent' 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: '192.168.0.147', password: '20160329', ttl: 5 } as CacheOptions }, fsCache: { class: CacherComponent, options: { type: 'fs', ttl: 5 } as CacheOptions }, memcachedCache: { class: CacherComponent, options: { type: 'memcached', hosts: '192.168.0.4', 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) })