Closed campbellmc closed 2 months ago
Here's my quick and dirty test script: https://github.com/dxclabs/node-fetch-cache-test/blob/4992d88ecb2a9a96f7c8c35cc43cee12b90f1fc6/src/cache_times.ts
Hi, it looks like you are constructing a separate MemoryCache for every request. To get the behavior it sounds like you want, you must use the same MemoryCache instance for all requests. The default cache is a globally shared instance of MemoryCache.
Duh. Thanks. Yes that changes everything. It wasn't happening for disk or redis because they are persistent and global stores. If I change the script to reuse the cached fetch instance, I see the right results.
Hi. Was messing around with some timing checks and see different results for subsequent fetches with default shared memory cache (caching is obvious) vs custom memory cache (doesn't appear to cache).
Am I missing something?
Here's the output of my messing around...
With default memory cache it says it's cached (returnedFromCache is true, fetch time is much shorter):
import fetch from "node-fetch-cache";
yields the following:However, with the Custom Memory Cache, it doesn't appear to actually cache (returnedFromCache is false, fetch time is roughly the same):
and we get this result: