mirror of
https://github.com/rharkor/caching-for-turbo.git
synced 2025-06-08 01:37:01 +09:00
refactor: logs
This commit is contained in:
parent
061c9bd119
commit
341c576773
3 changed files with 10 additions and 10 deletions
6
src/lib/cache/index.ts
vendored
6
src/lib/cache/index.ts
vendored
|
@ -8,7 +8,7 @@ import {
|
|||
statSync
|
||||
} from 'node:fs'
|
||||
import { getCacheClient } from './utils'
|
||||
import { cacheVersion, getCacheKey, getFsCachePath } from '../constants'
|
||||
import { cachePath, getCacheKey, getFsCachePath } from '../constants'
|
||||
|
||||
type RequestContext = {
|
||||
log: {
|
||||
|
@ -33,7 +33,7 @@ export async function saveCache(
|
|||
const client = getCacheClient()
|
||||
const existingCacheResponse = await client.reserve(
|
||||
getCacheKey(hash, tag),
|
||||
cacheVersion
|
||||
cachePath
|
||||
)
|
||||
|
||||
// Silently exit when we have not been able to receive a cache-hit
|
||||
|
@ -70,7 +70,7 @@ export async function getCache(
|
|||
//* Get cache from cache API
|
||||
const client = getCacheClient()
|
||||
const cacheKey = getCacheKey(hash)
|
||||
const { data } = await client.query(cacheKey, cacheVersion)
|
||||
const { data } = await client.query(cacheKey, cachePath)
|
||||
ctx.log.info(`Cache lookup for ${cacheKey}`)
|
||||
if (!data) {
|
||||
ctx.log.info(`Cache lookup did not return data`)
|
||||
|
|
12
src/lib/cache/utils.ts
vendored
12
src/lib/cache/utils.ts
vendored
|
@ -60,7 +60,7 @@ export function getCacheClient() {
|
|||
const { statusCode, statusText } = reserveCacheResponse
|
||||
const data = await reserveCacheResponse.readBody()
|
||||
const buildedError = new HandledError(statusCode, statusText, data)
|
||||
return handleFetchError('Unable to reserve cache')(buildedError)
|
||||
return handleFetchError(`Unable to reserve cache (status: ${statusCode} ${statusText})`)(buildedError)
|
||||
}
|
||||
} catch (error) {
|
||||
return handleFetchError('Unable to reserve cache')(error)
|
||||
|
@ -86,22 +86,22 @@ export function getCacheClient() {
|
|||
}
|
||||
|
||||
const query = async (
|
||||
keys: string,
|
||||
version: string
|
||||
key: string,
|
||||
path: string
|
||||
): Promise<{
|
||||
success: boolean
|
||||
data?: { cacheKey: string; archiveLocation: string }
|
||||
}> => {
|
||||
try {
|
||||
const queryCacheResponse = await cacheHttpClient.getCacheEntry(
|
||||
[keys],
|
||||
[version]
|
||||
[key],
|
||||
[path]
|
||||
)
|
||||
if (queryCacheResponse?.archiveLocation) {
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
cacheKey: keys,
|
||||
cacheKey: key,
|
||||
archiveLocation: queryCacheResponse.archiveLocation
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { join } from 'path'
|
|||
import { env } from './env'
|
||||
|
||||
export const serverPort = 41230
|
||||
export const cacheVersion = 'turbogha_v2'
|
||||
export const cachePath = 'turbogha_v2'
|
||||
export const cachePrefix = core.getInput('cache-prefix') || 'turbogha_'
|
||||
export const getCacheKey = (hash: string, tag?: string): string =>
|
||||
`${cachePrefix}${hash}${tag ? `#${tag}` : ''}`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue