Skip to content

duojs/cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

duo-cache

NPM version build status

The cache duo uses internally during builds.

API

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.

Cache(location)

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

Cache#read()

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

Cache#update(mapping)

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

Cache#file(id, [data])

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)

Cache#plugin(name, key, [data])

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;

Cache#clean()

Closes the database and wipes it out from the disk.

Roadmap

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)

About

The cache duo uses internally during builds

Resources

Stars

Watchers

Forks

Packages

No packages published