Skip to content

Commit

Permalink
update cache on query change
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Jan 24, 2019
1 parent 425b445 commit cc8aec0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions packages/gatsby-plugin-sharp/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@ const getQueueFromCache = async cache => {
return new Map(rawQueue)
}

exports.onPreInit = async ({ actions }, pluginOptions) => {
setBoundActionCreators(actions)
setPluginOptions(pluginOptions)
}

/**
* save queue to the cache
*/
exports.onPostBootstrap = async ({ cache }) => {
const saveQueueToCache = async cache => {
const cachedQueue = await getQueueFromCache(cache)

// merge both queues
Expand All @@ -37,6 +29,16 @@ exports.onPostBootstrap = async ({ cache }) => {
return cache.set(`queue`, Array.from(queue))
}

exports.onPreInit = async ({ actions }, pluginOptions) => {
setBoundActionCreators(actions)
setPluginOptions(pluginOptions)
}

/**
* save queue to the cache
*/
exports.onPostBootstrap = async ({ cache, store }) => saveQueueToCache(cache)

/**
* Execute all unprocessed images on gatsby build
*/
Expand All @@ -62,7 +64,11 @@ exports.onPostBuild = ({ cache, reporter }) =>
/**
* Build images on the fly when they are requested by the browser
*/
exports.onCreateDevServer = ({ app, cache }, pluginOptions) => {
exports.onCreateDevServer = async ({ app, cache, compiler }, pluginOptions) => {
compiler.hooks.done.tap(`Gatsby`, () => {
saveQueueToCache(cache)
})

app.use(async (req, res, next) => {
const queue = await getQueueFromCache(cache)
if (!queue.has(req.originalUrl)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/commands/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ async function startServer(program) {
})
}

await apiRunnerNode(`onCreateDevServer`, { app })
await apiRunnerNode(`onCreateDevServer`, { app, compiler })

// Render an HTML page and serve it.
app.use((req, res, next) => {
Expand Down

0 comments on commit cc8aec0

Please sign in to comment.