Skip to content

Commit

Permalink
resolve import cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Dec 4, 2023
1 parent 9d3bd68 commit 825e012
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/utilities/caching/caches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ function schedule(cache: CommonCache<any, any>) {
*/

export class CleanWeakCache<K extends WeakKey, V> extends WeakCache<K, V> {
constructor(max: number, dispose?: (value: V) => void) {
super(max, dispose);
}
set(key: K, value: V) {
schedule(this);
return super.set(key, value);
Expand All @@ -40,6 +43,9 @@ export class CleanWeakCache<K extends WeakKey, V> extends WeakCache<K, V> {
*/

export class CleanStrongCache<K, V> extends StrongCache<K, V> {
constructor(max: number, dispose?: (value: V) => void) {
super(max, dispose);
}
set(key: K, value: V) {
schedule(this);
return super.set(key, value);
Expand Down
6 changes: 4 additions & 2 deletions src/utilities/common/canonicalStringify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CleanStrongCache } from "../../utilities/index.js";
import { CleanStrongCache, cacheSizes } from "../../utilities/caching/index.js";

/**
* Like JSON.stringify, but with object keys always sorted in the same order.
Expand Down Expand Up @@ -26,7 +26,9 @@ export const canonicalStringify = Object.assign(
// Clearing the sortingMap will reclaim all cached memory, without
// affecting the logical results of canonicalStringify, but potentially
// sacrificing performance until the cache is refilled.
sortingMap = new CleanStrongCache<string, readonly string[]>();
sortingMap = new CleanStrongCache<string, readonly string[]>(
cacheSizes.canonicalStringify
);
},
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/graphql/print.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ASTNode } from "graphql";
import { print as origPrint } from "graphql";
import { CleanWeakCache, cacheSizes } from "../../utilities/index.js";
import { CleanWeakCache, cacheSizes } from "../caching/index.js";

let printCache!: CleanWeakCache<ASTNode, string>;
export const print = Object.assign(
Expand Down

0 comments on commit 825e012

Please sign in to comment.