Skip to content

Commit 4b116fd

Browse files
author
Chris Jensen
committed
Add cache directives to routes with safe caching patterns
- Public key endpoints cache for 5 minutes (CACHE_SHORT_PRIVATE) - Immutable media blobs cache for 1 year (CACHE_IMMUTABLE_PRIVATE) - Public testimonials cache for 60 seconds (CACHE_SHORT_PUBLIC) - All other routes default to no-store
1 parent ef94c06 commit 4b116fd

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

services/media/src/routes/media.routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
NotFoundError,
1010
ValidationError,
1111
} from '@speakeasy-services/common';
12+
import { CACHE_IMMUTABLE_PRIVATE } from '@speakeasy-services/service-base';
1213

1314
type Response = Parameters<RequestHandler>[1];
1415
import {
@@ -125,6 +126,7 @@ const methodHandlers = {
125126

126127
const stream = await getFromS3(key);
127128
res.setHeader('Content-Type', record.mimeType);
129+
res.setHeader('Cache-Control', CACHE_IMMUTABLE_PRIVATE);
128130
res.status(200);
129131
await pipeline(stream, res);
130132

services/service-admin/src/routes/testimonials.routes.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ValidationError,
1010
validateAgainstLexicon,
1111
} from '@speakeasy-services/common';
12+
import { CACHE_SHORT_PUBLIC } from '@speakeasy-services/service-base';
1213
import {
1314
checkContributionDef,
1415
createTestimonialDef,
@@ -190,12 +191,16 @@ const methodHandlers = {
190191
} as const;
191192

192193
// Define methods using XRPC lexicon
193-
export const methods: Record<MethodName, { handler: RequestHandler }> = {
194+
export const methods: Record<
195+
MethodName,
196+
{ handler: RequestHandler; cacheControl?: string }
197+
> = {
194198
'social.spkeasy.actor.createTestimonial': {
195199
handler: methodHandlers['social.spkeasy.actor.createTestimonial'],
196200
},
197201
'social.spkeasy.actor.listTestimonials': {
198202
handler: methodHandlers['social.spkeasy.actor.listTestimonials'],
203+
cacheControl: CACHE_SHORT_PUBLIC,
199204
},
200205
'social.spkeasy.actor.updateTestimonial': {
201206
handler: methodHandlers['social.spkeasy.actor.updateTestimonial'],

services/user-keys/src/routes/key.routes.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
User,
1515
getSessionDid,
1616
} from '@speakeasy-services/common';
17+
import { CACHE_SHORT_PRIVATE } from '@speakeasy-services/service-base';
1718
import {
1819
getPublicKeyDef,
1920
getPrivateKeysDef,
@@ -153,12 +154,17 @@ const methodHandlers = {
153154

154155
type MethodName = keyof typeof methodHandlers;
155156

156-
export const methods: Record<MethodName, { handler: RequestHandler }> = {
157+
export const methods: Record<
158+
MethodName,
159+
{ handler: RequestHandler; cacheControl?: string }
160+
> = {
157161
'social.spkeasy.key.getPublicKey': {
158162
handler: methodHandlers['social.spkeasy.key.getPublicKey'],
163+
cacheControl: CACHE_SHORT_PRIVATE,
159164
},
160165
'social.spkeasy.key.getPublicKeys': {
161166
handler: methodHandlers['social.spkeasy.key.getPublicKeys'],
167+
cacheControl: CACHE_SHORT_PRIVATE,
162168
},
163169
'social.spkeasy.key.getPrivateKey': {
164170
handler: methodHandlers['social.spkeasy.key.getPrivateKey'],

0 commit comments

Comments
 (0)