Tsed: [Request] Cache system

Created on 3 Aug 2019  路  1Comment  路  Source: tsedio/tsed

Information

  • Version: 5.x

Description

Leaving that for example database systems have their own cache system like for example TypeORM https://typeorm.io/#/caching, I think you should add some cache system with their own decorators.

Example: https://github.com/kwhitley/apicache
Cache types/strategies: https://scotch.io/tutorials/how-to-optimize-node-requests-with-simple-caching-strategies#toc-results-and-recommendation

question

Most helpful comment

Hello @chiqui3d,

You can implement your own decorator to cache request and choose your prefered lib to doing that.

Example with apicache:

import apicache from 'apicache'

let cache = apicache.middleware

@Controller('/')
class MyController {

   @Get()
   @UseBefore(cache('5 minutes'))
   getSomething(){
   }
}

You can implement your own decorator like that:

import apicache from 'apicache'

const cache = apicache.middleware

export function Cache(option: string) {
   return UseBefore(cache(options))
}

And use it on controller or method:

@Controller('/')
@Cache('5 minutes')// here 
class MyController {

   @Get()
   @Cache('5 minutes') // or here
   getSomething(){
   }
}

I think theses examples will help you!

If you want develop an official package for Tsed and provide a Cache strategy, you 're welcom :)

See you
Romain

>All comments

Hello @chiqui3d,

You can implement your own decorator to cache request and choose your prefered lib to doing that.

Example with apicache:

import apicache from 'apicache'

let cache = apicache.middleware

@Controller('/')
class MyController {

   @Get()
   @UseBefore(cache('5 minutes'))
   getSomething(){
   }
}

You can implement your own decorator like that:

import apicache from 'apicache'

const cache = apicache.middleware

export function Cache(option: string) {
   return UseBefore(cache(options))
}

And use it on controller or method:

@Controller('/')
@Cache('5 minutes')// here 
class MyController {

   @Get()
   @Cache('5 minutes') // or here
   getSomething(){
   }
}

I think theses examples will help you!

If you want develop an official package for Tsed and provide a Cache strategy, you 're welcom :)

See you
Romain

Was this page helpful?
0 / 5 - 0 ratings