@lage-run/cache 1.4.12 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -24,11 +24,12 @@ function _define_property(obj, key, value) {
|
|
|
24
24
|
class RemoteFallbackCacheProvider {
|
|
25
25
|
async fetch(hash, target) {
|
|
26
26
|
const { logger, remoteCacheProvider, localCacheProvider } = this.options;
|
|
27
|
+
const skipRemoteCacheForTarget = target.skipRemoteCache === true;
|
|
27
28
|
if (localCacheProvider) {
|
|
28
29
|
RemoteFallbackCacheProvider.localHits[hash] = await localCacheProvider.fetch(hash, target);
|
|
29
30
|
logger.silly(`local cache fetch: ${hash} ${RemoteFallbackCacheProvider.localHits[hash]}`);
|
|
30
31
|
}
|
|
31
|
-
if (!RemoteFallbackCacheProvider.localHits[hash] && remoteCacheProvider) {
|
|
32
|
+
if (!skipRemoteCacheForTarget && !RemoteFallbackCacheProvider.localHits[hash] && remoteCacheProvider) {
|
|
32
33
|
RemoteFallbackCacheProvider.remoteHits[hash] = await remoteCacheProvider.fetch(hash, target);
|
|
33
34
|
logger.silly(`remote fallback fetch: ${hash} ${RemoteFallbackCacheProvider.remoteHits[hash]}`);
|
|
34
35
|
// now save this into the localCacheProvider, if available
|
|
@@ -49,8 +50,14 @@ class RemoteFallbackCacheProvider {
|
|
|
49
50
|
logger.silly(`local cache put: ${hash}`);
|
|
50
51
|
putPromises.push(localCacheProvider.put(hash, target));
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Write to remote if:
|
|
55
|
+
* - the target has not disabled remote caching
|
|
56
|
+
* - there is no hit in the remote cache
|
|
57
|
+
* - a remote cache storage provider exists
|
|
58
|
+
* - the "writeRemoteCache" config flag is set to true
|
|
59
|
+
*/ const skipRemoteCacheForTarget = target.skipRemoteCache === true;
|
|
60
|
+
const shouldWriteRemoteCache = !skipRemoteCacheForTarget && !this.isRemoteHit(hash) && !!remoteCacheProvider && writeRemoteCache;
|
|
54
61
|
if (shouldWriteRemoteCache) {
|
|
55
62
|
logger.silly(`remote fallback put: ${hash}`);
|
|
56
63
|
const remotePut = remoteCacheProvider.put(hash, target);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/providers/RemoteFallbackCacheProvider.ts"],"sourcesContent":["import type { CacheProvider } from \"../types/CacheProvider.js\";\nimport type { Logger } from \"@lage-run/logger\";\nimport type { Target } from \"@lage-run/target-graph\";\n\nexport interface RemoteFallbackCacheProviderOptions {\n root: string;\n logger: Logger;\n\n localCacheProvider?: CacheProvider;\n remoteCacheProvider?: CacheProvider;\n\n writeRemoteCache?: boolean;\n}\n\n/**\n * Remote Fallback Cache Provider\n *\n * This backfill cache provider will fallback to a remote cache provider if the local cache does not contain the item.\n * It will also automatically populate the local cache with the remote cache.\n */\nexport class RemoteFallbackCacheProvider implements CacheProvider {\n private static localHits: { [hash: string]: boolean } = {};\n private static remoteHits: { [hash: string]: boolean } = {};\n\n constructor(private options: RemoteFallbackCacheProviderOptions) {}\n\n public async fetch(hash: string, target: Target): Promise<boolean> {\n const { logger, remoteCacheProvider, localCacheProvider } = this.options;\n\n if (localCacheProvider) {\n RemoteFallbackCacheProvider.localHits[hash] = await localCacheProvider.fetch(hash, target);\n logger.silly(`local cache fetch: ${hash} ${RemoteFallbackCacheProvider.localHits[hash]}`);\n }\n\n if (!RemoteFallbackCacheProvider.localHits[hash] && remoteCacheProvider) {\n RemoteFallbackCacheProvider.remoteHits[hash] = await remoteCacheProvider.fetch(hash, target);\n logger.silly(`remote fallback fetch: ${hash} ${RemoteFallbackCacheProvider.remoteHits[hash]}`);\n\n // now save this into the localCacheProvider, if available\n if (localCacheProvider && RemoteFallbackCacheProvider.remoteHits[hash]) {\n logger.silly(`local cache put, fetched cache from remote: ${hash}`);\n await localCacheProvider.put(hash, target);\n }\n\n return RemoteFallbackCacheProvider.remoteHits[hash];\n }\n\n return RemoteFallbackCacheProvider.localHits[hash];\n }\n\n public async put(hash: string, target: Target): Promise<void> {\n const { logger, remoteCacheProvider, localCacheProvider, writeRemoteCache } = this.options;\n const putPromises: Promise<void>[] = [];\n\n // Write local cache if it doesn't already exist, or if the the hash isn't in the localHits\n const shouldWriteLocalCache = !this.isLocalHit(hash) && !!localCacheProvider;\n\n if (shouldWriteLocalCache) {\n logger.silly(`local cache put: ${hash}`);\n putPromises.push(localCacheProvider.put(hash, target));\n }\n\n
|
|
1
|
+
{"version":3,"sources":["../../src/providers/RemoteFallbackCacheProvider.ts"],"sourcesContent":["import type { CacheProvider } from \"../types/CacheProvider.js\";\nimport type { Logger } from \"@lage-run/logger\";\nimport type { Target } from \"@lage-run/target-graph\";\n\nexport interface RemoteFallbackCacheProviderOptions {\n root: string;\n logger: Logger;\n\n localCacheProvider?: CacheProvider;\n remoteCacheProvider?: CacheProvider;\n\n writeRemoteCache?: boolean;\n}\n\n/**\n * Remote Fallback Cache Provider\n *\n * This backfill cache provider will fallback to a remote cache provider if the local cache does not contain the item.\n * It will also automatically populate the local cache with the remote cache.\n */\nexport class RemoteFallbackCacheProvider implements CacheProvider {\n private static localHits: { [hash: string]: boolean } = {};\n private static remoteHits: { [hash: string]: boolean } = {};\n\n constructor(private options: RemoteFallbackCacheProviderOptions) {}\n\n public async fetch(hash: string, target: Target): Promise<boolean> {\n const { logger, remoteCacheProvider, localCacheProvider } = this.options;\n const skipRemoteCacheForTarget = target.skipRemoteCache === true;\n\n if (localCacheProvider) {\n RemoteFallbackCacheProvider.localHits[hash] = await localCacheProvider.fetch(hash, target);\n logger.silly(`local cache fetch: ${hash} ${RemoteFallbackCacheProvider.localHits[hash]}`);\n }\n\n if (!skipRemoteCacheForTarget && !RemoteFallbackCacheProvider.localHits[hash] && remoteCacheProvider) {\n RemoteFallbackCacheProvider.remoteHits[hash] = await remoteCacheProvider.fetch(hash, target);\n logger.silly(`remote fallback fetch: ${hash} ${RemoteFallbackCacheProvider.remoteHits[hash]}`);\n\n // now save this into the localCacheProvider, if available\n if (localCacheProvider && RemoteFallbackCacheProvider.remoteHits[hash]) {\n logger.silly(`local cache put, fetched cache from remote: ${hash}`);\n await localCacheProvider.put(hash, target);\n }\n\n return RemoteFallbackCacheProvider.remoteHits[hash];\n }\n\n return RemoteFallbackCacheProvider.localHits[hash];\n }\n\n public async put(hash: string, target: Target): Promise<void> {\n const { logger, remoteCacheProvider, localCacheProvider, writeRemoteCache } = this.options;\n const putPromises: Promise<void>[] = [];\n\n // Write local cache if it doesn't already exist, or if the the hash isn't in the localHits\n const shouldWriteLocalCache = !this.isLocalHit(hash) && !!localCacheProvider;\n\n if (shouldWriteLocalCache) {\n logger.silly(`local cache put: ${hash}`);\n putPromises.push(localCacheProvider.put(hash, target));\n }\n\n /**\n * Write to remote if:\n * - the target has not disabled remote caching\n * - there is no hit in the remote cache\n * - a remote cache storage provider exists\n * - the \"writeRemoteCache\" config flag is set to true\n */\n const skipRemoteCacheForTarget = target.skipRemoteCache === true;\n const shouldWriteRemoteCache = !skipRemoteCacheForTarget && !this.isRemoteHit(hash) && !!remoteCacheProvider && writeRemoteCache;\n\n if (shouldWriteRemoteCache) {\n logger.silly(`remote fallback put: ${hash}`);\n const remotePut = remoteCacheProvider.put(hash, target);\n putPromises.push(remotePut);\n }\n\n await Promise.all(putPromises);\n }\n\n private isRemoteHit(hash: string) {\n return hash in RemoteFallbackCacheProvider.remoteHits && RemoteFallbackCacheProvider.remoteHits[hash];\n }\n\n private isLocalHit(hash: string) {\n return hash in RemoteFallbackCacheProvider.localHits && RemoteFallbackCacheProvider.localHits[hash];\n }\n\n public async clear(): Promise<void> {\n const { localCacheProvider } = this.options;\n if (localCacheProvider) {\n return localCacheProvider.clear();\n }\n }\n\n public async purge(sinceDays: number): Promise<void> {\n const { localCacheProvider } = this.options;\n if (localCacheProvider) {\n return localCacheProvider.purge(sinceDays);\n }\n }\n}\n"],"names":["RemoteFallbackCacheProvider","fetch","hash","target","logger","remoteCacheProvider","localCacheProvider","options","skipRemoteCacheForTarget","skipRemoteCache","localHits","silly","remoteHits","put","writeRemoteCache","putPromises","shouldWriteLocalCache","isLocalHit","push","shouldWriteRemoteCache","isRemoteHit","remotePut","Promise","all","clear","purge","sinceDays"],"mappings":";;;;+BAoBaA;;;eAAAA;;;;;;;;;;;;;;;;AAAN,MAAMA;IAMX,MAAaC,MAAMC,IAAY,EAAEC,MAAc,EAAoB;QACjE,MAAM,EAAEC,MAAM,EAAEC,mBAAmB,EAAEC,kBAAkB,EAAE,GAAG,IAAI,CAACC,OAAO;QACxE,MAAMC,2BAA2BL,OAAOM,eAAe,KAAK;QAE5D,IAAIH,oBAAoB;YACtBN,4BAA4BU,SAAS,CAACR,KAAK,GAAG,MAAMI,mBAAmBL,KAAK,CAACC,MAAMC;YACnFC,OAAOO,KAAK,CAAC,CAAC,mBAAmB,EAAET,KAAK,CAAC,EAAEF,4BAA4BU,SAAS,CAACR,KAAK,EAAE;QAC1F;QAEA,IAAI,CAACM,4BAA4B,CAACR,4BAA4BU,SAAS,CAACR,KAAK,IAAIG,qBAAqB;YACpGL,4BAA4BY,UAAU,CAACV,KAAK,GAAG,MAAMG,oBAAoBJ,KAAK,CAACC,MAAMC;YACrFC,OAAOO,KAAK,CAAC,CAAC,uBAAuB,EAAET,KAAK,CAAC,EAAEF,4BAA4BY,UAAU,CAACV,KAAK,EAAE;YAE7F,0DAA0D;YAC1D,IAAII,sBAAsBN,4BAA4BY,UAAU,CAACV,KAAK,EAAE;gBACtEE,OAAOO,KAAK,CAAC,CAAC,4CAA4C,EAAET,MAAM;gBAClE,MAAMI,mBAAmBO,GAAG,CAACX,MAAMC;YACrC;YAEA,OAAOH,4BAA4BY,UAAU,CAACV,KAAK;QACrD;QAEA,OAAOF,4BAA4BU,SAAS,CAACR,KAAK;IACpD;IAEA,MAAaW,IAAIX,IAAY,EAAEC,MAAc,EAAiB;QAC5D,MAAM,EAAEC,MAAM,EAAEC,mBAAmB,EAAEC,kBAAkB,EAAEQ,gBAAgB,EAAE,GAAG,IA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aAAyC,CAAC;AACzD,iBAFWV,6BAEIY,cAA0C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lage-run/cache",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Cache for Lage",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@azure/core-auth": "^1.9.0",
|
|
23
23
|
"@azure/identity": "^4.9.1",
|
|
24
|
-
"@lage-run/config": "^0.9.
|
|
25
|
-
"@lage-run/logger": "^1.
|
|
26
|
-
"@lage-run/target-graph": "^0.
|
|
24
|
+
"@lage-run/config": "^0.9.4",
|
|
25
|
+
"@lage-run/logger": "^1.4.0",
|
|
26
|
+
"@lage-run/target-graph": "^0.15.0",
|
|
27
27
|
"backfill-cache": "^5.12.3",
|
|
28
28
|
"backfill-config": "^6.7.2",
|
|
29
29
|
"backfill-logger": "^5.4.1",
|