duo-cache

The cache duo uses internally

duo-cache

The cache duo uses internally during builds.

This cache uses LevelDB internally (via level). The idea behind this cache is to help speed up duo's builds by storing data on disk so it can be read quickly later.

The location refers to the destination of the LevelDB database directory.

Reads the all the stored files from the database into memory.

Accepts the updated in-memory mapping and saves all the files into cache.

Can be used to set/get a single file's data from the cache. If data is excluded, it is assumed to be a getter. (otherwise, it will be a setter)

Can be used to set/get a plugin's cache data. If data is excluded, it is assumed to be a getter. (otherwise, it will be a setter)

The name should be the same as the plugin's name, to make debugging easier. The key can be either a String or an Array. Below is a sample plugin that is using caching.

// hash the source code as well as options to allow this 
// to work even if the user changes their config! 
var key = [ hash(src), hash(options) ];
 
// see if it's already been cached 
var cached = yield cache.plugin('plugin', key); // get 
if (cached) return cached;
 
// run the normal transformation 
var results = plugin(src, options);
// cache the results for next time 
yield cache.plugin('plugin', key, results); // set 
return results;

Closes the database and wipes it out from the disk.

Currently, this implementation only satisfies the bare-minimum based on duo's current cache implementation. (currently called the "mapping")

Now that there is a robust data-store in place, more features will be added, including:

  • give plugins a way to get/set cache data (so they can reduce the amount of processing they do on repeated builds)
  • store additional processing during the build process (such as the result of scanning a file for dependencies)
  • expose this hook to other modules that cache results (eg: gh-resolve)