mirror of
https://github.com/Swatinem/rust-cache
synced 2025-04-29 06:35:53 +00:00
chore: use 8 character hash components (#143)
Use 8 character hash components to reduce the key length, making it more readable. Fixes #97
This commit is contained in:
parent
ad97570a01
commit
bb80d0f127
4 changed files with 38 additions and 6 deletions
|
@ -13,6 +13,7 @@ const HOME = os.homedir();
|
|||
export const CARGO_HOME = process.env.CARGO_HOME || path.join(HOME, ".cargo");
|
||||
|
||||
const STATE_CONFIG = "RUST_CACHE_CONFIG";
|
||||
const HASH_LENGTH = 8;
|
||||
|
||||
export class CacheConfig {
|
||||
/** All the paths we want to cache */
|
||||
|
@ -105,7 +106,7 @@ export class CacheConfig {
|
|||
|
||||
self.keyEnvs = keyEnvs;
|
||||
|
||||
key += `-${hasher.digest("hex")}`;
|
||||
key += `-${digest(hasher)}`;
|
||||
|
||||
self.restoreKey = key;
|
||||
|
||||
|
@ -144,7 +145,7 @@ export class CacheConfig {
|
|||
hasher.update(chunk);
|
||||
}
|
||||
}
|
||||
let lockHash = hasher.digest("hex");
|
||||
let lockHash = digest(hasher);
|
||||
|
||||
self.keyFiles = keyFiles;
|
||||
|
||||
|
@ -239,6 +240,16 @@ export function isCacheUpToDate(): boolean {
|
|||
return core.getState(STATE_CONFIG) === "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hex digest of the given hasher truncated to `HASH_LENGTH`.
|
||||
*
|
||||
* @param hasher The hasher to digest.
|
||||
* @returns The hex digest.
|
||||
*/
|
||||
function digest(hasher: crypto.Hash): string {
|
||||
return hasher.digest("hex").substring(0, HASH_LENGTH);
|
||||
}
|
||||
|
||||
interface RustVersion {
|
||||
host: string;
|
||||
release: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue