mirror of
https://github.com/rharkor/caching-for-turbo.git
synced 2025-06-08 01:37:01 +09:00
refactor: cache
This commit is contained in:
parent
f1d0381aa6
commit
e178d6cd2e
6 changed files with 25 additions and 27 deletions
4
dist/post/index.js
generated
vendored
4
dist/post/index.js
generated
vendored
|
@ -25665,12 +25665,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getTempCachePath = exports.getFsCachePath = exports.serverLogFile = exports.getCacheKey = exports.cachePrefix = exports.cacheVersion = exports.serverPort = void 0;
|
||||
exports.getTempCachePath = exports.getFsCachePath = exports.serverLogFile = exports.getCacheKey = exports.cachePrefix = exports.cachePath = exports.serverPort = void 0;
|
||||
const core = __importStar(__nccwpck_require__(7484));
|
||||
const path_1 = __nccwpck_require__(6928);
|
||||
const env_1 = __nccwpck_require__(1363);
|
||||
exports.serverPort = 41230;
|
||||
exports.cacheVersion = 'turbogha_v2';
|
||||
exports.cachePath = 'turbogha_v2';
|
||||
exports.cachePrefix = core.getInput('cache-prefix') || 'turbogha_';
|
||||
const getCacheKey = (hash, tag) => `${exports.cachePrefix}${hash}${tag ? `#${tag}` : ''}`;
|
||||
exports.getCacheKey = getCacheKey;
|
||||
|
|
2
dist/post/index.js.map
generated
vendored
2
dist/post/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
29
dist/setup/index.js
generated
vendored
29
dist/setup/index.js
generated
vendored
|
@ -120284,7 +120284,7 @@ async function saveCache(ctx, hash, tag, stream) {
|
|||
return;
|
||||
}
|
||||
const client = (0, utils_1.getCacheClient)();
|
||||
const existingCacheResponse = await client.reserve((0, constants_1.getCacheKey)(hash, tag), constants_1.cacheVersion);
|
||||
const existingCacheResponse = await client.reserve((0, constants_1.getCacheKey)(hash, tag), constants_1.cachePath);
|
||||
// Silently exit when we have not been able to receive a cache-hit
|
||||
if (existingCacheResponse.success === false) {
|
||||
return;
|
||||
|
@ -120294,7 +120294,7 @@ async function saveCache(ctx, hash, tag, stream) {
|
|||
throw new Error(`Unable to reserve cache (received: ${JSON.stringify(existingCacheResponse.data)})`);
|
||||
}
|
||||
ctx.log.info(`Reserved cache ${id}`);
|
||||
await client.save(parseInt(id), stream);
|
||||
await client.save(id, stream);
|
||||
ctx.log.info(`Saved cache ${id} for ${hash}`);
|
||||
}
|
||||
async function getCache(ctx, hash) {
|
||||
|
@ -120309,7 +120309,7 @@ async function getCache(ctx, hash) {
|
|||
//* Get cache from cache API
|
||||
const client = (0, utils_1.getCacheClient)();
|
||||
const cacheKey = (0, constants_1.getCacheKey)(hash);
|
||||
const { data } = await client.query(cacheKey, constants_1.cacheVersion);
|
||||
const { data } = await client.query(cacheKey, constants_1.cachePath);
|
||||
ctx.log.info(`Cache lookup for ${cacheKey}`);
|
||||
if (!data) {
|
||||
ctx.log.info(`Cache lookup did not return data`);
|
||||
|
@ -120408,10 +120408,10 @@ function getCacheClient() {
|
|||
if (!env_1.env.valid) {
|
||||
throw new Error('Cache API env vars are not set');
|
||||
}
|
||||
const reserve = async (key, version) => {
|
||||
const reserve = async (key, path) => {
|
||||
try {
|
||||
const reserveCacheResponse = await cacheHttpClient.reserveCache(key, [
|
||||
version
|
||||
path
|
||||
]);
|
||||
if (reserveCacheResponse?.result?.cacheId) {
|
||||
return {
|
||||
|
@ -120425,10 +120425,9 @@ function getCacheClient() {
|
|||
return { success: false };
|
||||
}
|
||||
else {
|
||||
const { statusCode, statusText } = reserveCacheResponse;
|
||||
const data = await reserveCacheResponse.readBody();
|
||||
const buildedError = new HandledError(statusCode, statusText, data);
|
||||
return handleFetchError('Unable to reserve cache')(buildedError);
|
||||
const { statusCode, error } = reserveCacheResponse;
|
||||
const buildedError = new HandledError(statusCode, error?.message || 'Unknown', reserveCacheResponse);
|
||||
return handleFetchError(`Unable to reserve cache (status: ${statusCode} ${reserveCacheResponse})`)(buildedError);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
@ -120451,14 +120450,14 @@ function getCacheClient() {
|
|||
handleFetchError('Unable to upload cache')(error);
|
||||
}
|
||||
};
|
||||
const query = async (keys, version) => {
|
||||
const query = async (key, path) => {
|
||||
try {
|
||||
const queryCacheResponse = await cacheHttpClient.getCacheEntry([keys], [version]);
|
||||
const queryCacheResponse = await cacheHttpClient.getCacheEntry([key], [path]);
|
||||
if (queryCacheResponse?.archiveLocation) {
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
cacheKey: keys,
|
||||
cacheKey: key,
|
||||
archiveLocation: queryCacheResponse.archiveLocation
|
||||
}
|
||||
};
|
||||
|
@ -120522,12 +120521,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getTempCachePath = exports.getFsCachePath = exports.serverLogFile = exports.getCacheKey = exports.cachePrefix = exports.cacheVersion = exports.serverPort = void 0;
|
||||
exports.getTempCachePath = exports.getFsCachePath = exports.serverLogFile = exports.getCacheKey = exports.cachePrefix = exports.cachePath = exports.serverPort = void 0;
|
||||
const core = __importStar(__nccwpck_require__(37484));
|
||||
const path_1 = __nccwpck_require__(16928);
|
||||
const env_1 = __nccwpck_require__(51363);
|
||||
exports.serverPort = 41230;
|
||||
exports.cacheVersion = 'turbogha_v2';
|
||||
exports.cachePath = 'turbogha_v2';
|
||||
exports.cachePrefix = core.getInput('cache-prefix') || 'turbogha_';
|
||||
const getCacheKey = (hash, tag) => `${exports.cachePrefix}${hash}${tag ? `#${tag}` : ''}`;
|
||||
exports.getCacheKey = getCacheKey;
|
||||
|
@ -120706,7 +120705,7 @@ async function launchServer(devRun) {
|
|||
stdio: ['ignore', out, err]
|
||||
});
|
||||
child.unref();
|
||||
core.info(`Cache version: ${constants_1.cacheVersion}`);
|
||||
core.info(`Cache version: ${constants_1.cachePath}`);
|
||||
core.info(`Cache prefix: ${constants_1.cachePrefix}`);
|
||||
core.info(`Launched child process: ${child.pid}`);
|
||||
core.info(`Server log file: ${constants_1.serverLogFile}`);
|
||||
|
|
2
dist/setup/index.js.map
generated
vendored
2
dist/setup/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
2
src/lib/cache/index.ts
vendored
2
src/lib/cache/index.ts
vendored
|
@ -50,7 +50,7 @@ export async function saveCache(
|
|||
)
|
||||
}
|
||||
ctx.log.info(`Reserved cache ${id}`)
|
||||
await client.save(parseInt(id), stream)
|
||||
await client.save(id, stream)
|
||||
ctx.log.info(`Saved cache ${id} for ${hash}`)
|
||||
}
|
||||
|
||||
|
|
13
src/lib/cache/utils.ts
vendored
13
src/lib/cache/utils.ts
vendored
|
@ -38,14 +38,14 @@ export function getCacheClient() {
|
|||
|
||||
const reserve = async (
|
||||
key: string,
|
||||
version: string
|
||||
path: string
|
||||
): Promise<{
|
||||
success: boolean
|
||||
data?: { cacheId: string }
|
||||
data?: { cacheId: number }
|
||||
}> => {
|
||||
try {
|
||||
const reserveCacheResponse = await cacheHttpClient.reserveCache(key, [
|
||||
version
|
||||
path
|
||||
])
|
||||
if (reserveCacheResponse?.result?.cacheId) {
|
||||
return {
|
||||
|
@ -57,10 +57,9 @@ export function getCacheClient() {
|
|||
} else if (reserveCacheResponse?.statusCode === 409) {
|
||||
return { success: false }
|
||||
} else {
|
||||
const { statusCode, statusText } = reserveCacheResponse
|
||||
const data = await reserveCacheResponse.readBody()
|
||||
const buildedError = new HandledError(statusCode, statusText, data)
|
||||
return handleFetchError(`Unable to reserve cache (status: ${statusCode} ${statusText})`)(buildedError)
|
||||
const { statusCode, error } = reserveCacheResponse
|
||||
const buildedError = new HandledError(statusCode, error?.message || 'Unknown', reserveCacheResponse)
|
||||
return handleFetchError(`Unable to reserve cache (status: ${statusCode} ${reserveCacheResponse})`)(buildedError)
|
||||
}
|
||||
} catch (error) {
|
||||
return handleFetchError('Unable to reserve cache')(error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue