1- import { log } from 'apify' ;
21import type { ActorDefinition } from 'apify-client' ;
32
43import { ApifyClient , getApifyAPIBaseUrl } from '../apify-client.js' ;
@@ -9,7 +8,7 @@ export async function isActorMCPServer(actorID: string, apifyToken: string): Pro
98}
109
1110export async function getActorsMCPServerPath ( actorID : string , apifyToken : string ) : Promise < string | undefined > {
12- const actorDefinition = await getFullActorDefinition ( actorID , apifyToken ) ;
11+ const actorDefinition = await getActorDefinition ( actorID , apifyToken ) ;
1312
1413 if ( 'webServerMcpPath' in actorDefinition && typeof actorDefinition . webServerMcpPath === 'string' ) {
1514 return actorDefinition . webServerMcpPath ;
@@ -27,32 +26,20 @@ export async function getActorsMCPServerURL(actorID: string, apifyToken: string)
2726 return `${ standbyUrl } ${ mcpPath } ` ;
2827}
2928
30- // ID does not change, so no TTL
31- export const actorIDCache : Record < string , string > = { } ;
3229/**
3330* Gets Actor ID from the Actor object.
3431*
3532* @param actorID
3633* @param apifyToken
3734*/
3835export async function getRealActorID ( actorID : string , apifyToken : string ) : Promise < string > {
39- if ( actorIDCache [ actorID ] ) {
40- log . debug ( `Actor ${ actorID } ID cache hit` ) ;
41- return actorIDCache [ actorID ] ;
42- }
43- log . debug ( `Actor ${ actorID } ID cache miss` ) ;
44-
4536 const apifyClient = new ApifyClient ( { token : apifyToken } ) ;
4637
4738 const actor = apifyClient . actor ( actorID ) ;
4839 const info = await actor . get ( ) ;
4940 if ( ! info ) {
5041 throw new Error ( `Actor ${ actorID } not found` ) ;
5142 }
52-
53- if ( ! actorIDCache [ actorID ] ) {
54- actorIDCache [ actorID ] = info . id ;
55- }
5643 return info . id ;
5744}
5845
@@ -69,29 +56,7 @@ export async function getActorStandbyURL(actorID: string, apifyToken: string, st
6956 return `https://${ actorRealID } .${ standbyBaseUrl } ` ;
7057}
7158
72- export const actorDefinitionCache : Record < string , {
73- timestamp : number ;
74- definition : ActorDefinition ;
75- } > = { } ;
76- export const ACTOR_DEFINITION_CACHE_TTL_MS = 1000 * 60 * 60 ; // 1 hour
77- /**
78- * Gets full Actor definition from the Apify API.
79- */
80- export async function getFullActorDefinition ( actorID : string , apifyToken : string ) : Promise < ActorDefinition > {
81- const cacheInTTL = Date . now ( ) - ( actorDefinitionCache [ actorID ] ?. timestamp || 0 ) < ACTOR_DEFINITION_CACHE_TTL_MS ;
82- // Hit the cache
83- if ( actorDefinitionCache [ actorID ]
84- && cacheInTTL ) {
85- log . debug ( `Actor ${ actorID } definition cache hit` ) ;
86- return actorDefinitionCache [ actorID ] . definition ;
87- }
88- // Refresh the cache after TTL expired
89- if ( actorDefinitionCache [ actorID ] && ! cacheInTTL ) {
90- log . debug ( `Actor ${ actorID } definition cache TTL expired, re-fetching` ) ;
91- } else {
92- log . debug ( `Actor ${ actorID } definition cache miss` ) ;
93- }
94-
59+ export async function getActorDefinition ( actorID : string , apifyToken : string ) : Promise < ActorDefinition > {
9560 const apifyClient = new ApifyClient ( { token : apifyToken } ) ;
9661 const actor = apifyClient . actor ( actorID ) ;
9762 const info = await actor . get ( ) ;
@@ -119,14 +84,5 @@ export async function getFullActorDefinition(actorID: string, apifyToken: string
11984 throw new Error ( `Actor default build ${ actorID } does not have Actor definition` ) ;
12085 }
12186
122- // If the Actor is public, we cache the definition
123- // This code branch is executed only on cache miss, so we know the cache entry is empty
124- if ( info . isPublic ) {
125- actorDefinitionCache [ actorID ] = {
126- timestamp : Date . now ( ) ,
127- definition : actorDefinition ,
128- } ;
129- }
130-
13187 return actorDefinition ;
13288}
0 commit comments