@@ -2,8 +2,11 @@ import { promisify } from 'node:util';
22import * as zlib from 'node:zlib' ;
33import type { PackOptions } from '../../../types.js' ;
44
5- const inflateAsync = promisify ( zlib . inflate ) ;
6- const deflateAsync = promisify ( zlib . deflate ) ;
5+ const compressAsync = promisify ( zlib . brotliCompress ) ;
6+ const decompressAsync = promisify ( zlib . brotliDecompress ) ;
7+
8+ // Balanced speed/ratio for in-memory cache
9+ const BROTLI_QUALITY = 4 ;
710
811interface CacheEntry {
912 value : Uint8Array ; // Compressed data
@@ -43,7 +46,7 @@ export class RequestCache<T> {
4346
4447 try {
4548 // Decompress and return the data
46- const decompressedData = await inflateAsync ( entry . value ) ;
49+ const decompressedData = await decompressAsync ( entry . value ) ;
4750 return JSON . parse ( decompressedData . toString ( 'utf8' ) ) ;
4851 } catch ( error ) {
4952 console . error ( 'Error decompressing cache entry:' , error ) ;
@@ -56,7 +59,12 @@ export class RequestCache<T> {
5659 try {
5760 // Convert data to JSON string and compress
5861 const jsonString = JSON . stringify ( value ) ;
59- const compressedData = await deflateAsync ( Buffer . from ( jsonString , 'utf8' ) ) ;
62+ const compressedData = await compressAsync ( jsonString , {
63+ params : {
64+ [ zlib . constants . BROTLI_PARAM_MODE ] : zlib . constants . BROTLI_MODE_TEXT ,
65+ [ zlib . constants . BROTLI_PARAM_QUALITY ] : BROTLI_QUALITY ,
66+ } ,
67+ } ) ;
6068
6169 this . cache . set ( key , {
6270 value : compressedData ,
0 commit comments