@@ -16,7 +16,6 @@ import { createRequire } from 'node:module';
1616import { autoRegisterArrowDecoder } from '../utils/codec.js' ;
1717import { getDefaultPythonPath } from '../utils/python.js' ;
1818import { getVenvBinDir , getVenvPythonExe } from '../utils/runtime.js' ;
19- import { globalCache } from '../utils/cache.js' ;
2019
2120import { BasePythonBridge } from './base-bridge.js' ;
2221import { RpcClient } from './rpc-client.js' ;
@@ -64,9 +63,6 @@ export interface NodeBridgeOptions {
6463 /** Inherit all environment variables from parent process. Default: false */
6564 inheritProcessEnv ?: boolean ;
6665
67- /** Enable result caching for pure functions. Default: false */
68- enableCache ?: boolean ;
69-
7066 /** Optional extra environment variables to pass to the Python subprocess. */
7167 env ?: Record < string , string | undefined > ;
7268
@@ -132,7 +128,6 @@ interface ResolvedOptions {
132128 timeoutMs : number ;
133129 queueTimeoutMs : number ;
134130 inheritProcessEnv : boolean ;
135- enableCache : boolean ;
136131 enableChunking : boolean ;
137132 env : Record < string , string | undefined > ;
138133 codec ?: CodecOptions ;
@@ -293,7 +288,6 @@ function normalizeWarmupCommands(commands: NodeBridgeOptions['warmupCommands']):
293288 * - Virtual environment support
294289 * - Full BridgeCodec validation (NaN/Infinity rejection, key validation)
295290 * - Automatic Arrow decoding for DataFrames/ndarrays
296- * - Optional result caching for pure functions
297291 * - Process warmup commands
298292 *
299293 * @example
@@ -314,7 +308,6 @@ function normalizeWarmupCommands(commands: NodeBridgeOptions['warmupCommands']):
314308 * const pooledBridge = new NodeBridge({
315309 * maxProcesses: 4,
316310 * maxConcurrentPerProcess: 2,
317- * enableCache: true,
318311 * });
319312 * await pooledBridge.init();
320313 * ```
@@ -352,7 +345,6 @@ export class NodeBridge extends BasePythonBridge {
352345 timeoutMs : options . timeoutMs ?? 30000 ,
353346 queueTimeoutMs : options . queueTimeoutMs ?? 30000 ,
354347 inheritProcessEnv : options . inheritProcessEnv ?? false ,
355- enableCache : options . enableCache ?? false ,
356348 enableChunking : options . enableChunking ?? true ,
357349 env : options . env ?? { } ,
358350 codec : options . codec ,
@@ -457,57 +449,12 @@ export class NodeBridge extends BasePythonBridge {
457449
458450 /**
459451 * Expose the held RpcClient to BasePythonBridge's shared delegating methods
460- * (instantiate/callMethod/disposeInstance/getBridgeInfo). call() is
461- * overridden below to layer caching on top.
452+ * (call/instantiate/callMethod/disposeInstance/getBridgeInfo).
462453 */
463454 protected getRpcClient ( ) : RpcClient {
464455 return this . rpc ;
465456 }
466457
467- /**
468- * Call a Python function, with optional result caching.
469- *
470- * Overrides BasePythonBridge.call() to layer the cache lookup/writeback on
471- * top of the shared delegation. Cache lookup stays FIRST so cache hits return
472- * without forcing init, preserving the pre-composition behavior.
473- */
474- override async call < T = unknown > (
475- module : string ,
476- functionName : string ,
477- args : unknown [ ] ,
478- kwargs ?: Record < string , unknown >
479- ) : Promise < T > {
480- // Check cache if enabled
481- if ( this . resolvedOptions . enableCache ) {
482- const cacheKey = this . safeCacheKey ( 'runtime_call' , module , functionName , args , kwargs ) ;
483- if ( cacheKey ) {
484- const cached = await globalCache . get < T > ( cacheKey ) ;
485- if ( cached !== null ) {
486- return cached ;
487- }
488- }
489-
490- // Execute and cache if pure function
491- const startTime = performance . now ( ) ;
492- await this . ensureReady ( ) ;
493- const result = await this . rpc . call < T > ( module , functionName , args , kwargs ) ;
494- const duration = performance . now ( ) - startTime ;
495-
496- if ( cacheKey && this . isPureFunctionCandidate ( functionName , args ) ) {
497- await globalCache . set ( cacheKey , result , {
498- computeTime : duration ,
499- dependencies : [ module ] ,
500- } ) ;
501- }
502-
503- return result ;
504- }
505-
506- // No caching - direct call
507- await this . ensureReady ( ) ;
508- return this . rpc . call < T > ( module , functionName , args , kwargs ) ;
509- }
510-
511458 // ===========================================================================
512459 // POOL STATISTICS
513460 // ===========================================================================
@@ -561,52 +508,6 @@ export class NodeBridge extends BasePythonBridge {
561508 busyWorkers : poolStats . totalInFlight ,
562509 } ;
563510 }
564-
565- // ===========================================================================
566- // PRIVATE HELPERS
567- // ===========================================================================
568-
569- /**
570- * Generate a cache key, returning null if generation fails.
571- */
572- private safeCacheKey ( prefix : string , ...inputs : unknown [ ] ) : string | null {
573- try {
574- return globalCache . generateKey ( prefix , ...inputs ) ;
575- } catch {
576- return null ;
577- }
578- }
579-
580- /**
581- * Heuristic to determine if function result should be cached.
582- */
583- private isPureFunctionCandidate ( functionName : string , args : unknown [ ] ) : boolean {
584- const pureFunctionPatterns = [
585- / ^ ( g e t | f e t c h | r e a d | l o a d | f i n d | s e a r c h | q u e r y | s e l e c t ) _ / i,
586- / ^ ( c o m p u t e | c a l c u l a t e | p r o c e s s | t r a n s f o r m | c o n v e r t ) _ / i,
587- / ^ ( e n c o d e | d e c o d e | s e r i a l i z e | d e s e r i a l i z e ) _ / i,
588- ] ;
589-
590- const impureFunctionPatterns = [
591- / ^ ( s e t | s a v e | w r i t e | u p d a t e | i n s e r t | d e l e t e | c r e a t e | m o d i f y ) _ / i,
592- / ^ ( s e n d | p o s t | p u t | p a t c h ) _ / i,
593- / r a n d o m | u u i d | t i m e s t a m p | n o w | c u r r e n t / i,
594- ] ;
595-
596- if ( impureFunctionPatterns . some ( pattern => pattern . test ( functionName ) ) ) {
597- return false ;
598- }
599-
600- if ( pureFunctionPatterns . some ( pattern => pattern . test ( functionName ) ) ) {
601- return true ;
602- }
603-
604- const hasComplexArgs = args . some (
605- arg => arg !== null && typeof arg === 'object' && ! ( arg instanceof Date )
606- ) ;
607-
608- return ! hasComplexArgs && args . length <= 3 ;
609- }
610511}
611512
612513// =============================================================================
0 commit comments