You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to use the same cacheable instance to wrap two functions with the same type of parameters, this situation occurs.
import{describe,expect,it}from'vitest'import{Cacheable}from'cacheable'describe('cache',()=>{it('wrap async function',async()=>{constcache=newCacheable()constplus=async(a: number,b: number)=>a+bconstplusCached=cache.wrap(plus,{ttl: 5*60*1000})constmultiply=async(a: number,b: number)=>a*bconstmultiplyCached=cache.wrap(multiply,{ttl: 5*60*1000})constres1=awaitplusCached(1,2)constres2=awaitmultiplyCached(1,2)expect(res1).toBe(3)// OKexpect(res2).toBe(2)// Failed: Expected 2 but received 3})})
I checked the source code and found that in this line, I could only use a static key or the hash value of the parameters, which does not allow me to distinguish between different functions.
I currently have two solutions. But I don't know if these are the best practices.
Is your feature request related to a problem? Please describe.
I am using the Wrap / Memoization for Sync and Async Functions of
cacheable
.When I try to use the same cacheable instance to wrap two functions with the same type of parameters, this situation occurs.
I checked the source code and found that in this line, I could only use a static key or the hash value of the parameters, which does not allow me to distinguish between different functions.
I currently have two solutions. But I don't know if these are the best practices.
prefix
.Describe the solution you'd like
Can an additional
keyPrefix
parameter be added, which will be prefixed to the actual cacheKey to distinguish between different functions?The text was updated successfully, but these errors were encountered: