Skip to content

Commit

Permalink
Add cache control header
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickid2018 committed Jul 1, 2024
1 parent 07c3111 commit 28f4998
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/routes/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ interface ResponseSchema {
}

function stateToString(blockState: BlockState): string {
if (blockState.properties) {
if (blockState.properties && Object.keys(blockState.properties).length > 0) {
return `${blockState.name}[${Object.entries(blockState.properties)
.sort(([key1], [key2]) => key1.localeCompare(key2))
.map(([key, value]) => `${key}=${value}`)
Expand Down Expand Up @@ -248,7 +248,7 @@ const EMPTY_STATE_DATA: StateData = {

const RESPONSE_CACHE = new LRUCache<string, StateData, BlockState>({
max: 2000,
memoMethod: (key, staleValue, options) => makeStateData(options.context),
memoMethod: (_key, _staleValue, options) => makeStateData(options.context),
})

function findOrMakeData(blockState: BlockState): StateData {
Expand Down Expand Up @@ -302,6 +302,7 @@ function makeStateData(blockState: BlockState): StateData {
if (Array.isArray(textureData)) {
texturesParsed.add(texture)
} else {
texturesParsed.add(texture)
textureData.frames.forEach((val) => texturesParsed.add(val))
}
}
Expand All @@ -328,6 +329,11 @@ function makeStateData(blockState: BlockState): StateData {

// Routes ------------------------------------------------------------------------------------------

app.use(async (c, next) => {
c.res.headers.set('Cache-Control', 'public, max-age=86400, s-maxage=604800')
await next()
})

app.post('/', zValidator('json', querySchema), (ctx) => {
const query = ctx.req.valid('json')
const response = { states: [], textures: {}, models: {} } as ResponseSchema
Expand Down

0 comments on commit 28f4998

Please sign in to comment.