@@ -14,11 +14,6 @@ export class MultiPointStrategy extends CacheStrategy {
1414 public determineOptimalCachePoints ( ) : CacheResult {
1515 // If prompt caching is disabled or no messages, return without cache points
1616 if ( ! this . config . usePromptCache || this . config . messages . length === 0 ) {
17- // logger.debug("Cache points not used: prompt caching disabled or no messages", {
18- // ctx: "cache-strategy",
19- // usePromptCache: this.config.usePromptCache,
20- // messageCount: this.config.messages.length,
21- // })
2217 return this . formatWithoutCachePoints ( )
2318 }
2419
@@ -27,71 +22,26 @@ export class MultiPointStrategy extends CacheStrategy {
2722 const minTokensPerPoint = this . config . modelInfo . minTokensPerCachePoint
2823 let remainingCachePoints : number = this . config . modelInfo . maxCachePoints
2924
30- // logger.debug("Starting cache point determination", {
31- // ctx: "cache-strategy",
32- // supportsSystemCache,
33- // supportsMessageCache,
34- // minTokensPerPoint,
35- // maxCachePoints: this.config.modelInfo.maxCachePoints,
36- // remainingCachePoints,
37- // messageCount: this.config.messages.length,
38- // })
39-
4025 // First, determine if we'll use a system cache point
4126 const useSystemCache =
4227 supportsSystemCache && this . config . systemPrompt && this . meetsMinTokenThreshold ( this . systemTokenCount )
4328
44- // logger.debug("System cache point evaluation", {
45- // ctx: "cache-strategy",
46- // supportsSystemCache,
47- // hasSystemPrompt: !!this.config.systemPrompt,
48- // systemTokenCount: this.systemTokenCount,
49- // minTokensRequired: this.config.modelInfo.minTokensPerCachePoint,
50- // meetsThreshold: this.meetsMinTokenThreshold(this.systemTokenCount),
51- // useSystemCache,
52- // })
53-
5429 // Handle system blocks
5530 let systemBlocks : SystemContentBlock [ ] = [ ]
5631 if ( this . config . systemPrompt ) {
5732 systemBlocks = [ { text : this . config . systemPrompt } as unknown as SystemContentBlock ]
5833 if ( useSystemCache ) {
59- // logger.debug("Adding cache point after system prompt", {
60- // ctx: "cache-strategy",
61- // systemTokenCount: this.systemTokenCount,
62- // })
6334 systemBlocks . push ( this . createCachePoint ( ) as unknown as SystemContentBlock )
6435 remainingCachePoints --
6536 }
6637 }
6738
6839 // If message caching isn't supported, return with just system caching
6940 if ( ! supportsMessageCache ) {
70- // logger.debug("Message caching not supported, using system caching only", {
71- // ctx: "cache-strategy",
72- // supportsMessageCache,
73- // })
7441 return this . formatResult ( systemBlocks , this . messagesToContentBlocks ( this . config . messages ) )
7542 }
7643
77- // Determine optimal cache point placements for messages
78- // logger.debug("Determining message cache points", {
79- // ctx: "cache-strategy",
80- // minTokensPerPoint,
81- // remainingCachePoints,
82- // messageCount: this.config.messages.length,
83- // hasPreviousPlacements: !!this.config.previousCachePointPlacements,
84- // previousPlacementsCount: this.config.previousCachePointPlacements?.length || 0,
85- // })
86-
8744 const placements = this . determineMessageCachePoints ( minTokensPerPoint , remainingCachePoints )
88-
89- // logger.debug("Cache point placements determined", {
90- // ctx: "cache-strategy",
91- // placementsCount: placements.length,
92- // placements: placements.map((p) => ({ index: p.index, tokensCovered: p.tokensCovered })),
93- // })
94-
9545 const messages = this . messagesToContentBlocks ( this . config . messages )
9646 let cacheResult = this . formatResult ( systemBlocks , this . applyCachePoints ( messages , placements ) )
9747
@@ -115,62 +65,29 @@ export class MultiPointStrategy extends CacheStrategy {
11565 remainingCachePoints : number ,
11666 ) : CachePointPlacement [ ] {
11767 if ( this . config . messages . length <= 1 ) {
118- // logger.debug("Not enough messages for cache points", {
119- // ctx: "cache-strategy",
120- // messageCount: this.config.messages.length,
121- // })
12268 return [ ]
12369 }
12470
12571 const placements : CachePointPlacement [ ] = [ ]
12672 const totalMessages = this . config . messages . length
12773 const previousPlacements = this . config . previousCachePointPlacements || [ ]
12874
129- // logger.debug("Starting message cache point determination", {
130- // ctx: "cache-strategy",
131- // totalMessages,
132- // previousPlacementsCount: previousPlacements.length,
133- // remainingCachePoints,
134- // })
135-
13675 // Special case: If previousPlacements is empty, place initial cache points
13776 if ( previousPlacements . length === 0 ) {
138- // logger.debug("No previous placements, determining initial cache points", {
139- // ctx: "cache-strategy",
140- // })
141-
14277 let currentIndex = 0
14378
14479 while ( currentIndex < totalMessages && remainingCachePoints > 0 ) {
145- // logger.debug("Finding optimal placement for range", {
146- // ctx: "cache-strategy",
147- // startIndex: currentIndex,
148- // endIndex: totalMessages - 1,
149- // minTokensPerPoint,
150- // })
151-
15280 const newPlacement = this . findOptimalPlacementForRange (
15381 currentIndex ,
15482 totalMessages - 1 ,
15583 minTokensPerPoint ,
15684 )
15785
15886 if ( newPlacement ) {
159- // logger.debug("Found optimal placement", {
160- // ctx: "cache-strategy",
161- // placementIndex: newPlacement.index,
162- // tokensCovered: newPlacement.tokensCovered,
163- // })
164-
16587 placements . push ( newPlacement )
16688 currentIndex = newPlacement . index + 1
16789 remainingCachePoints --
16890 } else {
169- // logger.debug("No suitable placement found in range", {
170- // ctx: "cache-strategy",
171- // startIndex: currentIndex,
172- // endIndex: totalMessages - 1,
173- // })
17491 break
17592 }
17693 }
@@ -244,16 +161,6 @@ export class MultiPointStrategy extends CacheStrategy {
244161 const requiredPercentageIncrease = 1.2 // 20% increase required
245162 const requiredTokenThreshold = smallestGap * requiredPercentageIncrease
246163
247- // logger.debug("Cache point decision", {
248- // ctx: "cache-strategy",
249- // newMessagesTokens,
250- // smallestGap,
251- // requiredTokenThreshold,
252- // shouldCombine: newMessagesTokens >= requiredTokenThreshold,
253- // lastPreviousIndex,
254- // totalMessages,
255- // })
256-
257164 if ( newMessagesTokens >= requiredTokenThreshold ) {
258165 // It's beneficial to combine cache points since new messages have significantly more tokens
259166 logger . info ( "Combining cache points is beneficial" , {
@@ -348,11 +255,6 @@ export class MultiPointStrategy extends CacheStrategy {
348255 minTokensPerPoint : number ,
349256 ) : CachePointPlacement | null {
350257 if ( startIndex >= endIndex ) {
351- // logger.debug("Invalid range for cache point placement", {
352- // ctx: "cache-strategy",
353- // startIndex,
354- // endIndex,
355- // })
356258 return null
357259 }
358260
@@ -365,14 +267,6 @@ export class MultiPointStrategy extends CacheStrategy {
365267 }
366268 }
367269
368- // logger.debug("Finding last user message in range", {
369- // ctx: "cache-strategy",
370- // startIndex,
371- // endIndex,
372- // lastUserMessageIndex,
373- // foundUserMessage: lastUserMessageIndex >= 0,
374- // })
375-
376270 if ( lastUserMessageIndex >= 0 ) {
377271 // Calculate the total tokens covered from the previous cache point (or start of conversation)
378272 // to this cache point. This ensures tokensCovered represents the full span of tokens
@@ -395,34 +289,10 @@ export class MultiPointStrategy extends CacheStrategy {
395289 . slice ( tokenStartIndex , lastUserMessageIndex + 1 )
396290 . reduce ( ( acc , curr ) => acc + this . estimateTokenCount ( curr ) , 0 )
397291
398- // logger.debug("Evaluating potential cache point", {
399- // ctx: "cache-strategy",
400- // messageIndex: lastUserMessageIndex,
401- // previousCachePointIndex,
402- // tokenStartIndex,
403- // totalTokensCovered,
404- // minTokensPerPoint,
405- // meetsThreshold: totalTokensCovered >= minTokensPerPoint,
406- // })
407-
408292 // Guard clause: ensure we have enough tokens to justify a cache point
409293 if ( totalTokensCovered < minTokensPerPoint ) {
410- // logger.debug("Not enough tokens for cache point", {
411- // ctx: "cache-strategy",
412- // totalTokensCovered,
413- // minTokensPerPoint,
414- // messageIndex: lastUserMessageIndex,
415- // })
416294 return null
417295 }
418-
419- // logger.debug("Creating cache point placement", {
420- // ctx: "cache-strategy",
421- // index: lastUserMessageIndex,
422- // tokensCovered: totalTokensCovered,
423- // messageRole: this.config.messages[lastUserMessageIndex].role,
424- // })
425-
426296 return {
427297 index : lastUserMessageIndex ,
428298 type : "message" ,
0 commit comments