gRPCExpress
is a gRPC-web caching library built with TypeScript. It enhances the native functionalities of the grpc-web
library by providing advanced caching capabilities.
- Enhanced Caching: Extends the grpc-web's ServiceClient class to incorporate advanced caching functionalities.
- Efficiency: A pub-sub pattern to sequence repetitive function calls, reducing network usage.
- Cost-aware Caching: An efficient algorithm that maintains cache size constraints while ensuring relevant data remains cached.
- Unit Testing: Tested using ViTest.
Before you begin, ensure you have the grpc-web
dependency installed in your project and the services stub generated with protoc.
protoc -I=protos stocks.proto --js_out=import_style=commonjs,binary:protos --grpc-web_out=import_style=commonjs+dts,mode=grpcweb:protos
Install the library using npm:
npm i @grpcexpress/grpcexpress
import { grpcExpressClient } from "@grpcexpress/grpcexpress";
const Client = grpcExpressClient(ServiceClient);
const client = new Client(url);
const response = await client.myMethod(message);
Set default cache duration (in ms) for all method calls, the default duration is 10 minutes:
const Client = grpcExpressClient(ServiceClient, 10000);
To skip caching for a particular call:
const response = await client.myMethod(message, {
cacheOptions: { cache: "nocache:" },
});
Specify a custom cache expiration duration (in ms) for a particular response:
const response = await client.myMethod(message, {
cacheOptions: { duration: 10000 },
});
This project is licensed under the MIT License.
Junwen Zhang Arthur Griffith Murat Agrali Shi Yu Liu