metro icon indicating copy to clipboard operation
metro copied to clipboard

Caching Examples

Open jwaldrip opened this issue 4 years ago • 2 comments

Are there good examples for FileStore and NetworkStore cache configurations in metro?

jwaldrip avatar Oct 25 '19 05:10 jwaldrip

Are there any updates on this after two years?

dukhinv-vendor avatar Aug 30 '21 16:08 dukhinv-vendor

I've managed to use FileStore on my project.

If you check this file, you will notice that the metro-cache module exports the FileStore class.

No documentation is given of the options needed to create a new instance of the FileStore, but inspecting on the constructor of the FileStore class, I concluded that the root option is the directory where the cache will be saved.

My goal was to save Metro's cache on the project's root directory, so that I could cache it between builds on CircleCI. Therefore, my metro.config.js on a React Native / Expo (managed) project looked like this:

const { resolve } = require('path');
const { FileStore } = require('metro-cache');

module.exports = (async () => ({
  cacheStores: [
    new FileStore({ root: resolve(__dirname, '.metro-cache') }),
  ],
}))();

Anyway, I can't see the NetworkStore class on the metro-cache package, maybe the HttpGetStore or HttpStore can fullfil that role?

Hope it helps

iaacosta avatar Feb 22 '22 13:02 iaacosta