Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7daeeca

Browse filesBrowse files
committed
chore: drop use of noOpInMemoryCache
1 parent 13a65c3 commit 7daeeca
Copy full SHA for 7daeeca

File tree

Expand file treeCollapse file tree

2 files changed

+9
-27
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-27
lines changed

‎src/run/storage/request-scoped-in-memory-cache.cts

Copy file name to clipboardExpand all lines: src/run/storage/request-scoped-in-memory-cache.cts
+6-24Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,37 +91,19 @@ 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+
if (!requestContext) return
106+
inMemoryLRUCache?.set(`${requestContext?.requestID}:${key}`, value ?? NullValue)
125107
},
126108
}
127109
}

‎src/run/storage/storage.cts

Copy file name to clipboardExpand all lines: src/run/storage/storage.cts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { type BlobType } from '../../shared/blob-types.cjs'
77
import { getTracer } from '../handlers/tracer.cjs'
88

99
import { 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

1212
const 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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.