# Two (or more) LRU caches for a Node.js app

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 ) {
}

export function detailThreadSetCache( key: string, value, duration: number ) {
}

• There is more than one LRU cache module available for Node.js. Please be specific. Also, it would be a good idea to add some context about how you are using these functions. At first glance, I would suggest just getting rid of all four functions. Oct 24 '16 at 15:35
• I added link to the lru module in question. Would be very curious to see how you would replace the functions, while still allowing use of several different caches. Oct 24 '16 at 15:49
• Like I said, just get rid of them, period. If you want to see specific examples of how to do that, then show your code. Otherwise, you're just asking for code to be written rather than asking for a code review. Oct 24 '16 at 15:51

As mentioned in the comments, remove the functions. Don't even go into OOP. As to why, they're simply unnecessary wrappers to your cache objects which you can just access directly. detailThreadCache.set is just as verbose as detailThreadSetCache.