File tree Expand file tree Collapse file tree 2 files changed +8
-27
lines changed Expand file tree Collapse file tree 2 files changed +8
-27
lines changed Original file line number Diff line number Diff line change @@ -91,37 +91,18 @@ interface RequestScopedInMemoryCache {
9191 set ( key : string , value : BlobType | null | Promise < BlobType | null > ) : void
9292}
9393
94- const noOpInMemoryCache : RequestScopedInMemoryCache = {
95- get ( ) : undefined {
96- // no-op
97- } ,
98- set ( ) {
99- // no-op
100- } ,
101- }
102-
103- export const getRequestSpecificInMemoryCache = ( ) : RequestScopedInMemoryCache => {
94+ export const getRequestScopedInMemoryCache = ( ) : RequestScopedInMemoryCache => {
10495 const requestContext = getRequestContext ( )
105- if ( ! requestContext ) {
106- // Fallback to a no-op store if we can't find request context
107- return noOpInMemoryCache
108- }
109-
11096 const inMemoryLRUCache = getInMemoryLRUCache ( )
111- if ( inMemoryLRUCache === null ) {
112- return noOpInMemoryCache
113- }
11497
11598 return {
11699 get ( key ) {
117- const inMemoryValue = inMemoryLRUCache . get ( `${ requestContext . requestID } :${ key } ` )
118- if ( inMemoryValue === NullValue ) {
119- return null
120- }
121- return inMemoryValue
100+ if ( ! requestContext ) return
101+ const value = inMemoryLRUCache ?. get ( `${ requestContext . requestID } :${ key } ` )
102+ return value === NullValue ? null : value
122103 } ,
123104 set ( key , value ) {
124- inMemoryLRUCache . set ( `${ requestContext . requestID } :${ key } ` , value ?? NullValue )
105+ inMemoryLRUCache ? .set ( `${ requestContext ? .requestID } :${ key } ` , value ?? NullValue )
125106 } ,
126107 }
127108}
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { type BlobType } from '../../shared/blob-types.cjs'
77import { getTracer } from '../handlers/tracer.cjs'
88
99import { getRegionalBlobStore } from './regional-blob-store.cjs'
10- import { getRequestSpecificInMemoryCache } from './request-scoped-in-memory-cache.cjs'
10+ import { getRequestScopedInMemoryCache } from './request-scoped-in-memory-cache.cjs'
1111
1212const encodeBlobKey = async ( key : string ) => {
1313 const { encodeBlobKey : encodeBlobKeyImpl } = await import ( '../../shared/blobkey.js' )
@@ -22,7 +22,7 @@ export const getMemoizedKeyValueStoreBackedByRegionalBlobStore = (
2222
2323 return {
2424 async get < T extends BlobType > ( key : string , otelSpanTitle : string ) : Promise < T | null > {
25- const inMemoryCache = getRequestSpecificInMemoryCache ( )
25+ const inMemoryCache = getRequestScopedInMemoryCache ( )
2626
2727 const memoizedValue = inMemoryCache . get ( key )
2828 if ( typeof memoizedValue !== 'undefined' ) {
@@ -41,7 +41,7 @@ export const getMemoizedKeyValueStoreBackedByRegionalBlobStore = (
4141 return getPromise
4242 } ,
4343 async set ( key : string , value : BlobType , otelSpanTitle : string ) {
44- const inMemoryCache = getRequestSpecificInMemoryCache ( )
44+ const inMemoryCache = getRequestScopedInMemoryCache ( )
4545
4646 inMemoryCache . set ( key , value )
4747
You can’t perform that action at this time.
0 commit comments