Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/helix-shared-tokencache/src/MemCachePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export class MemCachePlugin {
return this.base ? this.base.location : this.key;
}

getLastModified() {
return this.base?.getLastModified?.() ?? null;
}

async getPluginMetadata() {
const cache = this.#getOrCreateCache();
if (!cache.metadata && this.base) {
Expand Down
8 changes: 8 additions & 0 deletions packages/helix-shared-tokencache/src/S3CachePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export class S3CachePlugin {
Bucket: bucket,
Key: key,
}));
this.lastModified = res.LastModified;

let raw = await new Response(res.Body, {}).buffer();
if (secret) {
raw = decrypt(secret, raw).toString('utf-8');
Expand Down Expand Up @@ -142,6 +144,8 @@ export class S3CachePlugin {
Body: raw,
ContentType: secret ? 'application/octet-stream' : 'text/plain',
}));
// save a roundtrip to the server doing a HEAD
this.lastModified = new Date();
return true;
} catch (e) {
log.warn('s3: unable to serialize token cache', e);
Expand Down Expand Up @@ -185,6 +189,10 @@ export class S3CachePlugin {
get location() {
return `${this.bucket}/${this.key}`;
}

getLastModified() {
return this.lastModified;
}
}

S3CachePlugin.encrypt = encrypt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ describe('MemCachePlugin Test', () => {
assert.strictEqual(ret, true);
assert.strictEqual(ctx.token, '1234');
assert.deepStrictEqual(caches.get('foobar-key'), { data: JSON.stringify(data) });
assert.strictEqual(p.getLastModified(), null);
});

it('read the cache from base is missing', async () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/helix-shared-tokencache/test/S3CachePlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ describe('S3CachePlugin Test', () => {
key: 'myproject/auth-default/json',
secret: '',
});
const lastModified = new Date('Fri, 12 Jun 2026 14:44:36 GMT');

nock('https://test-bucket.s3.us-east-1.amazonaws.com')
.get('/myproject/auth-default/json?x-id=GetObject')
Expand All @@ -278,13 +279,16 @@ describe('S3CachePlugin Test', () => {
cachePluginMetadata: {
foo: 'bar',
},
}));
}), {
'last-modified': lastModified.toUTCString(),
});

const ctx = new MockTokenCacheContext({});
const ret = await p.beforeCacheAccess(ctx);
assert.strictEqual(ret, true);
assert.strictEqual(ctx.token, '1234');
assert.deepStrictEqual(await p.getPluginMetadata(), { foo: 'bar' });
assert.strictEqual(p.getLastModified().getTime(), lastModified.getTime());
});

it('read cache data from s3 with encryption', async () => {
Expand Down
Loading