@fastly/compute-js-static-publish 8.0.3-rc.1 → 8.0.3-rc.2

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.
package/CHANGELOG.md CHANGED
@@ -16,7 +16,7 @@ This file does not list v7 releases after 7.0.8, or v6 releases after 6.3.0. For
16
16
 
17
17
  ### Changed
18
18
 
19
- - S3 mode: the server keeps the files that it reads from storage in the Fastly cache for 1 year. It was 1 hour. With a response cache `maxAge` of 1 hour or more, a response-cache miss then usually also read the file from storage. The key of a file has the hash of its content, so a cached copy does not get out of date. The cached files have the new surrogate key `<publishId>-files`. A publish does not purge it. The settings and the index are still kept for 1 hour.
19
+ - S3 mode: the server keeps the files that it reads from storage in the Fastly cache for 1 year. It was 1 hour. With a response cache `maxAge` of 1 hour or more, a response-cache miss then usually also read the file from storage. The key of a file has the hash of its content, so a cached copy does not get out of date. The cached files have the new surrogate key `<publishId>-files`. A publish does not purge it. If a file or an index part does not exist in storage, the server removes the `404` from the cache of its POP at once, so that it is found when it is added. The settings and the index are still kept for 1 hour.
20
20
 
21
21
  ### Fixed
22
22
 
@@ -1 +1 @@
1
- {"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/server/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAiBA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,YAAY,EAEjB,KAAK,eAAe,EACpB,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;AAElF,eAAO,MAAM,kBAAkB,EAAE,sBAahC,CAAC;AAMF;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,gBAAgB,EAAE,MAAM,QAEtE;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6
+ import { purgeSurrogateKey } from 'fastly:compute';
7
+ import { env } from 'fastly:env';
6
8
  import { SecretStore } from 'fastly:secret-store';
7
9
  import { Sha256 } from '@aws-crypto/sha256-js';
8
10
  import { SignatureV4 } from '@smithy/signature-v4';
@@ -69,7 +71,7 @@ export function setS3CredentialsBuilder(s3CredentialsBuilder) {
69
71
  _s3CredentialsBuilder = s3CredentialsBuilder;
70
72
  }
71
73
  // The time, in seconds, that the readthrough cache keeps an object when
72
- // getEntry() does not give a TTL.
74
+ // getEntry() does not give a TTL (one hour).
73
75
  const DEFAULT_CACHE_TTL = 3600;
74
76
  // Attempts for a request that fails with a retryable status or a network error.
75
77
  const MAX_ATTEMPTS = 5;
@@ -157,15 +159,31 @@ export class S3StorageProvider {
157
159
  }
158
160
  }
159
161
  async getEntry(key, tags, options) {
162
+ const ttl = options?.ttl ?? DEFAULT_CACHE_TTL;
163
+ // A read with a TTL longer than DEFAULT_CACHE_TTL also gets a surrogate key
164
+ // for this object in this POP. If the object does not exist, the server
165
+ // purges this key, so that the cache does not keep the 404 for the long
166
+ // TTL. The key has the POP name, so the purge removes only the copy in
167
+ // this POP.
168
+ const popSurrogateKey = ttl > DEFAULT_CACHE_TTL ? `pop-${env('FASTLY_POP')}-${key}` : null;
169
+ const surrogateKeys = [...(tags ?? []), ...(popSurrogateKey != null ? [popSurrogateKey] : [])];
160
170
  const response = await this.fetchObject(key, {
161
171
  backend: this.s3FastlyBackendName ?? "s3_storage",
162
172
  cacheOverride: new CacheOverride({
163
- ttl: options?.ttl ?? DEFAULT_CACHE_TTL,
164
- surrogateKey: (tags ?? []).join(' ') || undefined,
173
+ ttl,
174
+ surrogateKey: surrogateKeys.join(' ') || undefined,
165
175
  }),
166
176
  });
167
177
  if (response.status === 404) {
168
178
  console.log("Object does not exist");
179
+ if (popSurrogateKey != null) {
180
+ try {
181
+ purgeSurrogateKey(popSurrogateKey);
182
+ }
183
+ catch (err) {
184
+ console.warn(`Could not purge the 404 of ${key} from the cache.`, err);
185
+ }
186
+ }
169
187
  return null;
170
188
  }
171
189
  if (!response.ok) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "8.0.3-rc.1",
4
+ "version": "8.0.3-rc.2",
5
5
  "description": "Static Publisher for Fastly Compute JavaScript",
6
6
  "main": "build/server/server/index.js",
7
7
  "exports": {