Skip to content

Commit

Permalink
fix(cache): clean up not reachable removal of deps
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Dec 7, 2023
1 parent a52bf00 commit c1cb4f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 0 additions & 6 deletions src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,6 @@ function deleteEntry(entry) {
setTimeout(() => {
for (const e of gc) {
if (!e.contexts || e.contexts.size === 0) {
if (e.deps) {
for (const depEntry of e.deps) {
depEntry.contexts.delete(e);
}
}

const targetMap = entries.get(e.target);
targetMap.delete(e.key);
}
Expand Down
16 changes: 15 additions & 1 deletion test/spec/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
observe,
} from "../../src/cache.js";

import { resolveRaf } from "../helpers.js";
import { resolveRaf, resolveTimeout } from "../helpers.js";

describe("cache:", () => {
let target;
Expand Down Expand Up @@ -166,6 +166,20 @@ describe("cache:", () => {

expect(spy).toHaveBeenCalledTimes(0);
});

it("deletes entry if it has no contexts", () => {
get(target, "key", () =>
get(target, "otherKey", () => get(target, "deepKey", () => "value")),
);
invalidate(target, "otherKey", { deleteEntry: true });

return resolveTimeout(() => {
expect(getEntries(target).map(({ key }) => key)).toEqual([
"key",
"deepKey",
]);
});
});
});

describe("invalidateAll()", () => {
Expand Down

0 comments on commit c1cb4f7

Please sign in to comment.