Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache behavior #237

Open
anywhichway opened this issue May 29, 2023 · 8 comments
Open

Cache behavior #237

anywhichway opened this issue May 29, 2023 · 8 comments

Comments

@anywhichway
Copy link

I would expect value to be 1 below because it would be reloaded. This does not seem to be the case.

await db.put(1,1);
db.cache.delete(1);
const value = db.get(1);
if(value!==1) console.log(new Error("Value is not 1"));

@kriszyp
Copy link
Owner

kriszyp commented May 29, 2023

I think I need a little more context, this code snippet works fine for me (returns 1).

@anywhichway
Copy link
Author

Hmmmm ... returns undefined for me. I will try to reproduce in an isolated manner.

@anywhichway
Copy link
Author

Looks like this was a case of another piece of code having side effects once caching was turned on. It had no side effects with caching off. Eliminated side effect. Eliminated issue. Sorry to have bothered you.

@anywhichway
Copy link
Author

Further info ... this situation only occurs under very high load, i.e. using benchtest. The value gets into the cache but the awaits on put never resolve. And, put is being called indirectly by my code, e.g. put.call(this,key,value).

I have walked into the source an commitPromise in write.js is the promise that is not resolving and does not seem to be throwing either.

I have reopened since I can reproduce now, even with the side-effects that were in my code removed. I am working on a standalone Benchtest file.

@anywhichway anywhichway reopened this May 30, 2023
@anywhichway
Copy link
Author

Definitively a side effect of using Benchtest:

This works:

await db.put(1,1);
 if(db.cache.has(key)) { // succeeds
      db.cache.delete(1);
     const value = db.get(1); // returns undefined
     if(key!==1) console.log(new Error("Key is not 1"));
   }

This does not:

suite.add("put primitive",async () => {
    await db.put(1,1);
   if(db.cache.has(key)) { // succeeds
      db.cache.delete(1);
     const value = db.get(1); // returns undefined
     if(key!==1) console.log(new Error("Key is not 1"));
   }
})

@kriszyp
Copy link
Owner

kriszyp commented May 30, 2023

Would I do something like import { suite } from 'benchtest'; to test this?

@anywhichway
Copy link
Author

anywhichway commented May 30, 2023 via email

@anywhichway
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants