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

Add the ability to store resources against individual pages in the cache for Build Time Render #459

Open
matt-gadd opened this issue Apr 23, 2021 · 0 comments

Comments

@matt-gadd
Copy link
Contributor

Enhancement
At the moment Build Time Render has the concept of a page cache, and appropriate cli options to manage it. This is non programmatic for the end user and is a literal cache of the output of a specific page.

It would be nice if users could programmatically attach resources that are scoped to a page, for example network requests. We could then offer the user to be able to evict those as part of evicting a page from the cache (or not). This would be extremely useful on request heavy pages where the data from the request doesn't often change, these requests are normally quite expensive in terms of rendering for Build Time Render.

To do this, we would have to introduce some kind of Build Time Render api set that can be used in blocks, this has been mused before for different scenarios (dojo/webpack-contrib#134).

For example usage something like this in a block:

import { cache } from '@dojo/framework/core/build'

const myBlock = async (url: string) => {
  // where 'current-page' is the scope, might be other options later like 'global'
  // where 'network-request' is a user defined key
  const myRequest = cache.get('current-page', 'network-request', url);
  if (myRequest) {
    return myRequest;
  }
  const response = await fetch(url);
  const json = await response.json();
  cache.set('current-page', 'network-request', url, { json });
  return json;
}

export default myBlock;

We can also potentially build higher level utilities on top of this in @dojo/framework, ie a fetchWithCache etc.

We would then want to supplement the existing page cache command options to be able to evict resources under a page, and list resources under a page too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant