Socket
Book a DemoInstallSign in
Socket

broccoli-caching-writer

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broccoli-caching-writer

Broccoli plugin that allows simple caching (while still allowing N:N) based on the input tree hash.

0.5.1
Source
npmnpm
Version published
Weekly downloads
288K
6.89%
Maintainers
1
Weekly downloads
 
Created

What is broccoli-caching-writer?

The broccoli-caching-writer package is a Broccoli plugin that provides a base class for Broccoli plugins that need to cache their output. It helps in optimizing build times by caching the results of expensive operations and reusing them when the input hasn't changed.

What are broccoli-caching-writer's main functionalities?

Caching Output

This feature allows you to create a custom Broccoli plugin that caches its output. The `updateCache` method is where you perform your expensive operations, and the results are cached for future builds.

const CachingWriter = require('broccoli-caching-writer');
const fs = require('fs');

class MyCachingWriter extends CachingWriter {
  updateCache(srcDir, destDir) {
    // Perform expensive operations here
    fs.writeFileSync(`${destDir}/output.txt`, 'Cached content');
  }
}

module.exports = MyCachingWriter;

Handling Multiple Input Nodes

This feature allows you to handle multiple input nodes. The `updateCache` method receives an array of source directories, enabling you to process multiple inputs and cache their results.

const CachingWriter = require('broccoli-caching-writer');
const fs = require('fs');

class MultiInputCachingWriter extends CachingWriter {
  constructor(inputNodes, options) {
    super(inputNodes, options);
  }

  updateCache(srcDirs, destDir) {
    // srcDirs is an array of input directories
    srcDirs.forEach((srcDir, index) => {
      fs.writeFileSync(`${destDir}/output${index}.txt`, `Cached content from ${srcDir}`);
    });
  }
}

module.exports = MultiInputCachingWriter;

Custom Cache Key

This feature allows you to define a custom cache key for your plugin. The `cacheKey` method generates a unique key that can be used to determine if the cache should be invalidated.

const CachingWriter = require('broccoli-caching-writer');
const fs = require('fs');
const crypto = require('crypto');

class CustomCacheKeyWriter extends CachingWriter {
  constructor(inputNodes, options) {
    super(inputNodes, options);
  }

  cacheKey() {
    // Generate a custom cache key
    return crypto.createHash('md5').update('custom-key').digest('hex');
  }

  updateCache(srcDir, destDir) {
    fs.writeFileSync(`${destDir}/output.txt`, 'Cached content with custom key');
  }
}

module.exports = CustomCacheKeyWriter;

Other packages similar to broccoli-caching-writer

Keywords

broccoli-plugin

FAQs

Package last updated on 09 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.