
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
data-point-cache
Advanced tools
DataPoint cache layer
Factory method to create a simple cache API that you can use for data persistence.
$ npm install data-point-cache
const Cache = require('data-point-cache')
Cache.create()
.then(cache => {
return cache.set('myKey', 'foo', '20m')
.then(() => {
return cache.get('myKey')
})
})
.then(result => {
console.log('foo')
)
This cache API has an in-memory storage mechanism. The idea here is that every time a get/set operation happens, a short (TTL of 2 seconds) in-memory version of that key will be stored. After the TTL of the in-memory key has expired, the key will be removed. The swiping mechanism triggers every second and will kill every key that has its TTL has expired. The idea behind this is to try to be as optimal with our requests to redis, but also be careful not to store for too long in the in-memory layer.
Like any software, see if this works for you and your use case before going to production.
Create a cache instance.
Cache.create({
localTTL: Number,
redis: Object,
}):Promise<cache>
This factory method returns a Promise that resolves to a cache instance.
option | type | required | description |
---|---|---|---|
localTTL | Number | optional | Value in Milliseconds of in memory TTL, by default is set to 2000 (2 seconds) |
redis | Object | optional | Value passed to the ioredis constructor |
Adds a new entry to the cache. This method
cache.set(key:String, value:Any, ttl:String):Promise
Returns a promise.
Parameter description:
arguments:
argument | type | required | description |
---|---|---|---|
key | String | yes | key related to this entry. |
value | Any | yes | Value to be stored, this value will be stringified when stored in redis. |
ttl | String | optional | Time To Live of the entry. Defaults to 20 minutes. |
This method gets an entry from the cache. Every time this method gets executed it will:
cache.get(key:String):Promise<Any|undefined>
Returns a promise, if the key does not exist it will resolve to undefined
.
Parameter description:
arguments:
argument | type | required | description |
---|---|---|---|
key | String | yes | key related to this entry. |
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
This project is licensed under the Apache License Version 2.0 - see the LICENSE file for details
FAQs
DataPoint Cache Layer
The npm package data-point-cache receives a total of 292 weekly downloads. As such, data-point-cache popularity was classified as not popular.
We found that data-point-cache demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.