Here is a caching code of a nodejs / typescript app using lru Cache module from https://www.npmjs.com/package/lru-cache. For various reason i need to setup separate caches: one for homeCache another one for detailThreadCache... but this is just the beginning I may need to set up more.
This code is working, but how would you refactor it to improve code reuse ? Would you use object oriented paradigm ? If yes how ?
const homeCache = lruCache( 50 )
const detailThreadCache = lruCache( 150 )
export function homeCachedData( key ) {
return homeCache.get( key )
}
export function homeSetCache( key: string, value, duration: number ) {
homeCache.set( key, value, duration )
}
export function detailThreadGetCache( key ) {
return detailThreadCache.get( key )
}
export function detailThreadSetCache( key: string, value, duration: number ) {
detailThreadCache.set( key, value, duration )
}