Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
brave-cache
Advanced tools
Brave Cache is a simple, fast, and secure caching library manager for Nodejs.
NodeJs Ecosystem already has lots of caching libraries and this is not one of them, but they are not merge-able and consists of different apis.
For example lets assume i want to use two cache systems: redis
and node-cache
. Brave Cache supports adding multiple cache providers/drivers while keeping same api.
npm install brave-cache
# OR
yarn add brave-cache
const {BraveCache} = require('brave-cache');
const LRUCacheProvider = require('brave-cache/providers/lru-cache');
// Register Provider
BraveCache.registerProvider(LRUCacheProvider());
// Create Cache, it will use LRUCache
const cache = new BraveCache();
cache.set("test", "test");
console.log(cache.get("test"))
// You can also access the provider i.e lru-cache directly
cache.provider.client.set("direct", "direct") // => LRUCache
console.log(cache.get("direct")) // => direct
console.log(cache.provider.client.get("direct")) // => direct
BraveCache provides extra rare functions for managing multiple caches. By rare we mean functions not included in the majority of cache packages out there but required in modern day applications.
Basically all nodejs cache
modules have similar api, so creating a custom provider is easy.
A custom provider is a function that takes any necessary configuration and returns a BraveCacheProvider
class instance.
import BraveCacheProvider from "brave-cache/src/BraveCacheProvider";
function SimpleCache() {
// Holds cache values
let SimpleCacheStore = {};
// Return provider instance
return new BraveCacheProvider({
name,
functions: {
get(key) {
return SimpleCacheStore[key];
},
set(key, value) {
SimpleCacheStore[key] = value;
},
has(key) {
return SimpleCacheStore.hasOwnProperty(key);
},
remove(key) {
delete SimpleCacheStore[key];
},
flush() {
SimpleCacheStore = {};
}
}
});
}
From the example above, the SimpleCache
provider is a simple implementation of how to create a cache Provider.
Notice that you have to implement all the functions that are required by the BraveCacheProvider
class.
These functions will be used when accessing the cache.
const {BraveCache} = require('brave-cache');
// Register Simple Cache Above
BraveCache.registerProvider(SimpleCache());
const cache = new BraveCache(); // or new BraveCache("simple-cache"); if simple-cache is not set as default provider.
cache.set("test", "test");
console.log(cache.get("test"))
More implementations can be found in test files
FAQs
A flexible semantic Api for handling multiple node cache drivers.
The npm package brave-cache receives a total of 6 weekly downloads. As such, brave-cache popularity was classified as not popular.
We found that brave-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.