The Wayback Machine - https://web.archive.org/web/20201001170049/https://github.com/mintere/mega-cache-node
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Mega Cache

A speedy & extensible library designed for caching large numbers of large blobs in memory and on disk. Used heavily in production by Mintere for serving web content at scale.

Based on jhuckaby's megahash.

Install

npm i --save mega-cache

or

yarn add mega-cache

Documentation.

Usage

You'll probably want to use the MegaCache - it's the flagship cache of the library, and for good reason. The MegaCache caches in both memory and disk and automatically takes care of expiring the least recently used entries.

Values must be Buffers.

Keys must be strings or Buffers.

import {MegaCache, cacheSource, MiB} from "mega-cache";

const source = cacheSource(async (key) => {
  console.log("loading key...");
  return Buffer.from("*".repeat(10 * MiB))
}); 

const cache = new MegaCache({
  source: source,
  maxMemoryDataSize: 25 * MiB, // The maximum amount of RAM to use for caching.
  cacheDir: ".cache",          // Which directory to use for disk cache.
  maxFSBinSize: 60 * MiB,      // Use up-to 3x this amount of disk space.
  maxFSEntries: 10,            // Use up-to 3x this number of files.
});

cache.get("test") //=> Buffer, Prints "Loading Key"
cache.get("test") //=> Buffer
cache.get("test-1") //=> Buffer, Prints "Loading Key"


cache.close() // You should do this in order to ensure cache files are removed.

While we recommend the MegaCache for most use-cases, the library is extremely versatile. You should read the documentation.

License

Copyright © 2020 Mintere LLC, All rights reserved.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

About

A speedy extensible library for caching large blobs (<2GB) in memory and on disk

Topics

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.