MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add og image caching

+12 -2
+12 -2
docs/reports/src/index.ts
··· 167 167 app.get('/og/:image', async c => { 168 168 const db = drizzle(c.env.DB); 169 169 const id = ogImageId(c.req.param('image')); 170 + 171 + const cache = caches.default; 172 + const cacheKey = new Request(publicOgImageUrl(c.req.url, id), { method: 'GET' }); 173 + 174 + const cached = await cache.match(cacheKey); 175 + if (cached) return cached; 176 + 170 177 const report = await getReport(db, id); 171 178 if (!report) return c.notFound(); 172 179 ··· 176 183 await getOgFontBytes(c.env, c.req.url), 177 184 ); 178 185 179 - return c.body(png, 200, { 186 + const response = c.body(png, 200, { 180 187 'Content-Type': 'image/png', 181 - 'Cache-Control': 'public, max-age=3600', 188 + 'Cache-Control': 'public, max-age=2592000, immutable', 182 189 }); 190 + 191 + c.executionCtx.waitUntil(cache.put(cacheKey, response.clone())); 192 + return response; 183 193 }); 184 194 185 195 app.get('/:id', async c => {