
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
@extensionengine/tapster
Advanced tools
Cache adapter module for NodeJs.
npm install @extensionengine/tapster
const { CacheManager } = require('@extensionengine/tapster');
const cache = new CacheManager({ /* ... */ });
memory
(uses LRU)redis
(uses ioredis)See examples below and in the examples directory.
const client = new CacheManager({ store: 'memory', ttl: 10 /* seconds */ });
// If the set method is called without ttl, the default ttl will be used
await client.set('foo', 'bar');
await client.get('foo'); // bar
await client.has('foo') // true
await client.has('baz'); // false
await sleep('10s');
await client.get('foo'); // undefined
await client.has('foo') // false
// When ttl is defined, it will overwrite the default one
await client.set('foo', 'bar', 5);
await client.has('foo') // true
await sleep('5s');
await client.has('foo') // false
// ttl = 0 means no expiration time
await client.set('foo', 'bar', 0);
const client = new CacheManager({
store: 'redis',
host: 'localhost',
port: 6379,
ttl: 10 /* seconds */
});
await client.set('foo', 'bar');
await client.get('foo'); // bar
You can use your own custom store by creating one with the same API as the built-in memory stores (such as a memory or redis). See example.
class CustomStore { /* ... */ }
const client = new CacheManager({ store: CustomStore });
await client.set('foo', 'bar');
await client.get('foo'); // bar
Tapster uses JSON.stringify
and JSON.parse
for data serialization.
You can optionally provide your own serialization functions to support extra data types or to serialize to something other than JSON.
const cache = new CacheManager({ serialize: JSON.stringify, deserialize: JSON.parse });
Namespacing cache instance enables avoiding key collisions and allows clearing only a certain namespace while using the same database.
const users = new CacheManager({ namespace: 'users' });
const cars = new CacheManager({ namespace: 'cars' });
await users.set('record-1', 'John');
await cars.set('record-1', 'Honda');
console.log('User keys: ', await users.getKeys()); // ['record-1'];
console.log(await users.get('record-1')); // John
console.log('Car keys: ', await cars.getKeys()); // ['record-1']
console.log(await cars.get('record-1')); // Honda
await users.clear();
console.log('User keys: ', await users.getKeys()); // []
console.log(await users.get('record-1')); // undefined
console.log('Car keys: ', await cars.getKeys()); // ['record-1']
console.log(await cars.get('record-1')); // Honda
store
(optional) - built-in store (memory
, redis
) or custom store. Default is memory
.ttl
(optional) - time to live in seconds. Default is 0
.namespace
(optional) - namespace cache instance to avoid key collisions. Default is default
.host
(required) - redis host.port
(required) - redis port.password
(optional) - redis password.set(key, value, ttl)
- TTL is optional. The cache manager instance's TTL will be used if the set method is called without a ttl parameter.get(key) => value
delete(key)
has(key)
clear
- Clear all records under the certain namespacegetKeys(pattern) => keys
Supported glob-style patterns:
To run tests run:
npm t
Tapster is licensed under the MIT license.
FAQs
Cache adapter module for NodeJs
The npm package @extensionengine/tapster receives a total of 2 weekly downloads. As such, @extensionengine/tapster popularity was classified as not popular.
We found that @extensionengine/tapster demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 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
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.