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

fix(gatsby): Add directory to GatsbyCacheLmdb #32391

Merged
merged 4 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/__tests__/cache-lmdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describeWhenLMDB(`cache-lmdb`, () => {

beforeAll(async () => {
const { default: GatsbyCacheLmdb } = await import(`../cache-lmdb`)
cache = new GatsbyCacheLmdb({ name: `__test__` })
cache = new GatsbyCacheLmdb({ name: `__test__` }).init()
const fileDir = path.join(
process.cwd(),
`.cache/caches-lmdb-${process.env.JEST_WORKER_ID}`
Expand Down
9 changes: 9 additions & 0 deletions packages/gatsby/src/utils/cache-lmdb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { open, RootDatabase, Database } from "lmdb-store"
import fs from "fs-extra"
import path from "path"

// Since the regular GatsbyCache saves to "caches" this should be "caches-lmdb"
Expand All @@ -16,9 +17,17 @@ export default class GatsbyCacheLmdb {
private static store
private db: Database | undefined
public readonly name: string
// Needed for plugins that want to write data to the cache directory
public readonly directory: string

constructor({ name = `db` }: { name: string }) {
this.name = name
this.directory = path.join(process.cwd(), `.cache/caches/${name}`)
pieh marked this conversation as resolved.
Show resolved Hide resolved
}

init(): GatsbyCacheLmdb {
fs.ensureDirSync(this.directory)
return this
}

private static getStore(): RootDatabase {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/get-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const getCache = (name: string): GatsbyCache => {
if (!cache) {
if (isLmdbStore()) {
const GatsbyCacheLmdb = require(`./cache-lmdb`).default
cache = new GatsbyCacheLmdb({ name }) as GatsbyCache
cache = new GatsbyCacheLmdb({ name }).init() as GatsbyCache
} else {
cache = new GatsbyCache({ name }).init()
}
Expand Down