New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

async-cache-dedupe

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-cache-dedupe - npm Package Compare versions

Comparing version

to
1.7.0

index.d.ts

8

package.json
{
"name": "async-cache-dedupe",
"version": "1.6.0",
"version": "1.7.0",
"description": "An async deduping cache",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "standard | snazzy && tap test/*test.js",
"test": "standard | snazzy && tap test/*test.js && tsd",
"lint:fix": "standard --fix",

@@ -36,3 +37,4 @@ "redis": "docker run --rm -p 6379:6379 redis redis-server"

"standard": "^17.0.0",
"tap": "^16.3.0"
"tap": "^16.3.0",
"tsd": "^0.25.0"
},

@@ -39,0 +41,0 @@ "dependencies": {

@@ -282,2 +282,32 @@ # async-cache-dedupe

## TypeScript
This module provides a basic type definition for TypeScript.
As the library does some meta-programming and magic stuff behind the scenes, your compiler could yell at you when defining functions using the `define` property.
To avoid this, our suggestion is to use a [`Union Type`](https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html) in combination with the given `Cache` type as below:
```ts
import { createCache } from 'async-cache-dedupe'
const fetchSomething = async (k: any) => {
console.log("query", k);
return { k };
};
export type CachedFunctions = {
fetchSomething: typeof fetchSomething;
}; // <--- This is where you define all the functions you want to cache
const cache = createCache({
ttl: 5, // seconds
storage: { type: 'memory' },
}) as Cache & CachedFunctions // <--- This is where you tell the compiler to consider both the Cache type and your custom type
cache.define('fetchSomething', fetchSomething)
const p1 = cache.fetchSomething(42) // <--- TypeScript doesn't argue anymore here!
```
---
## Maintainers

@@ -284,0 +314,0 @@