Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
brave-cache
Advanced tools
Brave Cache is a simple 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. Brave Cache supports adding multiple cache providers/drivers while keeping same api.
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.
npm install brave-cache
# OR
yarn add brave-cache
const BraveCache = require('brave-cache');
const LRUCacheProvider = require('brave-cache/providers/lru-cache');
// Register a Provider
BraveCache.registerProvider(LRUCacheProvider({
// LRU Cache Options
}));
// 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
These are the functions available on the cache instance.
Example of a cache instance.
Out of the box, BraveCache provides supports for the following cache libraries:
lru-cache
)node-cache
)The default Provider is ObjectCacheProvider
which uses object-collection
to store the cache data in an object.
It has been registered by default.
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.
const BraveCacheProvider = require("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);
},
del(key) {
delete SimpleCacheStore[key];
},
flush() {
SimpleCacheStore = {};
},
keys() {
return Object.keys(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.
A custom Provider function can include arguments that are related to the provider.
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", "value");
console.log(cache.get("test")) // => value
FAQs
A flexible semantic Api for handling multiple node cache drivers.
The npm package brave-cache receives a total of 17 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.