
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
The map-cache npm package is a simple cache to store key-value pairs. It is particularly useful for storing the results of expensive function calls or any other calculations that you don't want to repeat unnecessarily. It's a lightweight and fast caching solution.
Set and Get Values
This feature allows you to store a value with a specific key and then retrieve that value using the key.
{"const MapCache = require('map-cache');
const cache = new MapCache();
cache.set('foo', 'bar');
const value = cache.get('foo');
console.log(value); // Output: 'bar'"}
Check Existence of Key
This feature allows you to check if a key exists in the cache.
{"const MapCache = require('map-cache');
const cache = new MapCache();
cache.set('foo', 'bar');
const hasKey = cache.has('foo');
console.log(hasKey); // Output: true"}
Delete a Key
This feature allows you to delete a key-value pair from the cache.
{"const MapCache = require('map-cache');
const cache = new MapCache();
cache.set('foo', 'bar');
cache.delete('foo');
const value = cache.get('foo');
console.log(value); // Output: undefined"}
Clear the Cache
This feature allows you to clear all key-value pairs stored in the cache.
{"const MapCache = require('map-cache');
const cache = new MapCache();
cache.set('foo', 'bar');
cache.clear();
const value = cache.get('foo');
console.log(value); // Output: undefined"}
lru-cache is an npm package that implements a cache object that deletes the least-recently-used items. It is similar to map-cache but with the added feature of maintaining a limited size and evicting entries that have not been recently used.
node-cache is an in-memory cache module for Node.js. It is similar to map-cache but provides additional features like TTL (time to live) for entries, statistics about the cache's performance, and events for when entries expire.
memory-cache is another simple in-memory cache for Node.js applications. It is similar to map-cache but also offers the ability to set a timeout on cached items, after which they are automatically removed.
Basic cache object for storing key-value pairs.
Install with npm:
$ npm install map-cache --save
Based on MapCache in Lo-dash v3.0. MIT License
var MapCache = require('map-cache');
var mapCache = new MapCache();
Creates a cache object to store key/value pairs.
Example
var cache = new MapCache();
Adds value
to key
on the cache.
Params
key
{String}: The key of the value to cache.value
{any}: The value to cache.returns
{Object}: Returns the Cache
object for chaining.Example
cache.set('foo', 'bar');
Gets the cached value for key
.
Params
key
{String}: The key of the value to get.returns
{any}: Returns the cached value.Example
cache.get('foo');
//=> 'bar'
Checks if a cached value for key
exists.
Params
key
{String}: The key of the entry to check.returns
{Boolean}: Returns true
if an entry for key
exists, else false
.Example
cache.has('foo');
//=> true
Removes key
and its value from the cache.
Params
key
{String}: The key of the value to remove.returns
{Boolean}: Returns true
if the entry was removed successfully, else false
.Example
cache.del('foo');
You might also be interested in these projects:
get
, set
, del
, and has
methods for node.js/javascript projects. | homepagePull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Install dev dependencies:
$ npm install -d && npm test
Jon Schlinkert
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb, v0.9.0, on May 10, 2016.
FAQs
Basic cache object for storing key-value pairs.
The npm package map-cache receives a total of 20,834,163 weekly downloads. As such, map-cache popularity was classified as popular.
We found that map-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
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.