Skip to content

Commit

Permalink
fix(gatsby): Add directory to GatsbyCacheLmdb (#32391) (#32421)
Browse files Browse the repository at this point in the history
Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
Co-authored-by: Lennart <lekoarts@gmail.com>
  • Loading branch information
GatsbyJS Bot and LekoArts committed Jul 19, 2021
1 parent 1b45c7b commit 3d5bf37
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/__tests__/cache-lmdb.ts
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
@@ -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}`)
}

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
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

0 comments on commit 3d5bf37

Please sign in to comment.