Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bedrock-caches

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bedrock-caches

A collection of cache implementations for NodeJS

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Bedrock Cache Collection

This is a collection of cache implementations for use in your application, e.g. for caching template data. Modules are seperated into several files so only the things you need get loaded.

A list of cache implementations:

  • In-memory cache
  • JSON object file cache
  • Cache wrapper for dynamic values

API

Caches implement the Cache<K, V> interface, which makes it easy to implement your own caches.

Almost all caches have a constructor in the form of:

new Cache(options)

Where the options object contains the following keys:

  • fetch: function that will be used to fetch a value if the value was not found in the cache

The following methods are available on all caches:

cache.get(key)

Get the value associated with key, doing a fetch if the value was not found.

cache.hasCached(key)

Checks if the value is added to the local cache.

cache.fetch(key)

Does a direct fetch for the given key. The value is not stored in the cache.

cache.evict(key)

Removes the value stored at key from the cache. Will not report an error if no values were found.

new MemoryCache(options)

Creates a new cache that will store values in-memory.

import { MemoryCache } from "bedrock-caches/lib/memory"

new JSONFileCache(options)

Creates a new cache that serializes values onto disk.

  • cacheDir the directory to store the serialized objects
import { JSONFileCache } from "bedrock-caches/lib/json"

new UpdateCache(parentCache)

Creates a new cache that will listen to the change-event of its values and re-fetch as appropriate. The parentCache is used to store the values in.

import { UpdateCache } from "bedrock-caches/lib/update"

Limitations

  • Currently only supports synchronous caching

Keywords

FAQs

Package last updated on 20 Jul 2016

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc