zkat / cacache

💩💵 but for your data. If you've got the hash, we've got the cache ™ (moved)

Home Page:https://github.com/npm/cacache

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memoization - Expected Cache Entry to Drop Past the Max Age

jfmartinez opened this issue · comments

Hello!

I decided to give the in-memory cache a try, it does keep the entries in memory but since it uses the lru-cache module and setting the maxAge to 3 minutes I expected the content to "fall out". Here are the steps (sample code is below)

  1. Added an entry to the cache
  2. Deleted the cache directory
  3. Waited 5 minutes
  4. Expect the entry to not be found since LRU cache drops the entry after maxAge.
const cacache = require('cacache');
const rimraf = require('rimraf');

const key = 'someKey';
const cachePath = './cache';

const opts = {
  memoize: true,
};
cacache.put(cachePath, key, 'hello world!', opts)
.then((integrity) => {
  console.log(integrity);
  rimraf(cachePath, () => {});
});

// Wait five minutes
setTimeout(() => {
  cacache.get(cachePath, key, opts)
.then(console.log);
}, 5 * 60 * 1000);

Details:

  • Node v4.7.2
  • npm v2.15
  • cacache v7.1.0

@jfmartinez Thanks for the report! That does seem super weird. Let me see if I can repro this with a plain old lru-cache and get back to you.

In the meantime, if you want to explicitly clear up space, consider using cacache.clearMemoized() to make it explicit!

ahahah no nevermind this is an obvious bug and it's really ridiculous that I made this mistake when I was moving from a plain object to lru-cache. Fixup forthcoming :)

@jfmartinez you can see the patch over at 0e55dc9. I'm gonna take this opportunity to add memoization object injection to cacache. Having a single global one isn't great in a lot of cases.

Thanks again for the report! :)

Looks great! Thank you for your quick response and fix.

Also, I was going to ask you about modifying the fixed lru-cache parameters but that option to pass in your own memoization object is a much better alternative 👍

Thanks!