added fonts

This commit is contained in:
guus committed 2025-07-02 11:28:41 +02:00
1 parent 4134e3a234
commit 142d2986b6
9079 files changed
+1498421 -2

No files matched your search

+107
View File
@@ -0,0 +1,107 @@
/**
* This is the default "use cache" handler it defaults to an in-memory store.
* In-memory caches are fragile and should not use stale-while-revalidate
* semantics on the caches because it's not worth warming up an entry that's
* likely going to get evicted before we get to use it anyway. However, we also
* don't want to reuse a stale entry for too long so stale entries should be
* considered expired/missing in such cache handlers.
*/ import { LRUCache } from '../lru-cache';
import { isStale, tagsManifest } from '../incremental-cache/tags-manifest.external';
// LRU cache default to max 50 MB but in future track
const memoryCache = new LRUCache(50 * 1024 * 1024, (entry)=>entry.size);
const pendingSets = new Map();
const debug = process.env.NEXT_PRIVATE_DEBUG_CACHE ? console.debug.bind(console, 'DefaultCacheHandler:') : undefined;
const DefaultCacheHandler = {
async get (cacheKey) {
const pendingPromise = pendingSets.get(cacheKey);
if (pendingPromise) {
debug == null ? void 0 : debug('get', cacheKey, 'pending');
await pendingPromise;
}
const privateEntry = memoryCache.get(cacheKey);
if (!privateEntry) {
debug == null ? void 0 : debug('get', cacheKey, 'not found');
return undefined;
}
const entry = privateEntry.entry;
if (performance.timeOrigin + performance.now() > entry.timestamp + entry.revalidate * 1000) {
// In-memory caches should expire after revalidate time because it is
// unlikely that a new entry will be able to be used before it is dropped
// from the cache.
debug == null ? void 0 : debug('get', cacheKey, 'expired');
return undefined;
}
if (isStale(entry.tags, entry.timestamp)) {
debug == null ? void 0 : debug('get', cacheKey, 'had stale tag');
return undefined;
}
const [returnStream, newSaved] = entry.value.tee();
entry.value = newSaved;
debug == null ? void 0 : debug('get', cacheKey, 'found', {
tags: entry.tags,
timestamp: entry.timestamp,
revalidate: entry.revalidate,
expire: entry.expire
});
return {
...entry,
value: returnStream
};
},
async set (cacheKey, pendingEntry) {
debug == null ? void 0 : debug('set', cacheKey, 'start');
let resolvePending = ()=>{};
const pendingPromise = new Promise((resolve)=>{
resolvePending = resolve;
});
pendingSets.set(cacheKey, pendingPromise);
const entry = await pendingEntry;
let size = 0;
try {
const [value, clonedValue] = entry.value.tee();
entry.value = value;
const reader = clonedValue.getReader();
for(let chunk; !(chunk = await reader.read()).done;){
size += Buffer.from(chunk.value).byteLength;
}
memoryCache.set(cacheKey, {
entry,
isErrored: false,
errorRetryCount: 0,
size
});
debug == null ? void 0 : debug('set', cacheKey, 'done');
} catch (err) {
// TODO: store partial buffer with error after we retry 3 times
debug == null ? void 0 : debug('set', cacheKey, 'failed', err);
} finally{
resolvePending();
pendingSets.delete(cacheKey);
}
},
async refreshTags () {
// Nothing to do for an in-memory cache handler.
},
async getExpiration (...tags) {
const expiration = Math.max(...tags.map((tag)=>tagsManifest.get(tag) ?? 0));
debug == null ? void 0 : debug('getExpiration', {
tags,
expiration
});
return expiration;
},
async expireTags (...tags) {
const timestamp = Math.round(performance.timeOrigin + performance.now());
debug == null ? void 0 : debug('expireTags', {
tags,
timestamp
});
for (const tag of tags){
// TODO: update file-system-cache?
tagsManifest.set(tag, timestamp);
}
}
};
export default DefaultCacheHandler;
//# sourceMappingURL=default.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/cache-handlers/default.ts"],"sourcesContent":["/**\n * This is the default \"use cache\" handler it defaults to an in-memory store.\n * In-memory caches are fragile and should not use stale-while-revalidate\n * semantics on the caches because it's not worth warming up an entry that's\n * likely going to get evicted before we get to use it anyway. However, we also\n * don't want to reuse a stale entry for too long so stale entries should be\n * considered expired/missing in such cache handlers.\n */\n\nimport { LRUCache } from '../lru-cache'\nimport type { CacheEntry, CacheHandlerV2 } from './types'\nimport {\n isStale,\n tagsManifest,\n} from '../incremental-cache/tags-manifest.external'\n\ntype PrivateCacheEntry = {\n entry: CacheEntry\n\n // For the default cache we store errored cache\n // entries and allow them to be used up to 3 times\n // after that we want to dispose it and try for fresh\n\n // If an entry is errored we return no entry\n // three times so that we retry hitting origin (MISS)\n // and then if it still fails to set after the third we\n // return the errored content and use expiration of\n // Math.min(30, entry.expiration)\n isErrored: boolean\n errorRetryCount: number\n\n // compute size on set since we need to read size\n // of the ReadableStream for LRU evicting\n size: number\n}\n\n// LRU cache default to max 50 MB but in future track\nconst memoryCache = new LRUCache<PrivateCacheEntry>(\n 50 * 1024 * 1024,\n (entry) => entry.size\n)\nconst pendingSets = new Map<string, Promise<void>>()\n\nconst debug = process.env.NEXT_PRIVATE_DEBUG_CACHE\n ? console.debug.bind(console, 'DefaultCacheHandler:')\n : undefined\n\nconst DefaultCacheHandler: CacheHandlerV2 = {\n async get(cacheKey) {\n const pendingPromise = pendingSets.get(cacheKey)\n\n if (pendingPromise) {\n debug?.('get', cacheKey, 'pending')\n await pendingPromise\n }\n\n const privateEntry = memoryCache.get(cacheKey)\n\n if (!privateEntry) {\n debug?.('get', cacheKey, 'not found')\n return undefined\n }\n\n const entry = privateEntry.entry\n if (\n performance.timeOrigin + performance.now() >\n entry.timestamp + entry.revalidate * 1000\n ) {\n // In-memory caches should expire after revalidate time because it is\n // unlikely that a new entry will be able to be used before it is dropped\n // from the cache.\n debug?.('get', cacheKey, 'expired')\n\n return undefined\n }\n\n if (isStale(entry.tags, entry.timestamp)) {\n debug?.('get', cacheKey, 'had stale tag')\n\n return undefined\n }\n const [returnStream, newSaved] = entry.value.tee()\n entry.value = newSaved\n\n debug?.('get', cacheKey, 'found', {\n tags: entry.tags,\n timestamp: entry.timestamp,\n revalidate: entry.revalidate,\n expire: entry.expire,\n })\n\n return {\n ...entry,\n value: returnStream,\n }\n },\n\n async set(cacheKey, pendingEntry) {\n debug?.('set', cacheKey, 'start')\n\n let resolvePending: () => void = () => {}\n const pendingPromise = new Promise<void>((resolve) => {\n resolvePending = resolve\n })\n pendingSets.set(cacheKey, pendingPromise)\n\n const entry = await pendingEntry\n\n let size = 0\n\n try {\n const [value, clonedValue] = entry.value.tee()\n entry.value = value\n const reader = clonedValue.getReader()\n\n for (let chunk; !(chunk = await reader.read()).done; ) {\n size += Buffer.from(chunk.value).byteLength\n }\n\n memoryCache.set(cacheKey, {\n entry,\n isErrored: false,\n errorRetryCount: 0,\n size,\n })\n\n debug?.('set', cacheKey, 'done')\n } catch (err) {\n // TODO: store partial buffer with error after we retry 3 times\n debug?.('set', cacheKey, 'failed', err)\n } finally {\n resolvePending()\n pendingSets.delete(cacheKey)\n }\n },\n\n async refreshTags() {\n // Nothing to do for an in-memory cache handler.\n },\n\n async getExpiration(...tags) {\n const expiration = Math.max(\n ...tags.map((tag) => tagsManifest.get(tag) ?? 0)\n )\n\n debug?.('getExpiration', { tags, expiration })\n\n return expiration\n },\n\n async expireTags(...tags) {\n const timestamp = Math.round(performance.timeOrigin + performance.now())\n debug?.('expireTags', { tags, timestamp })\n\n for (const tag of tags) {\n // TODO: update file-system-cache?\n tagsManifest.set(tag, timestamp)\n }\n },\n}\n\nexport default DefaultCacheHandler\n"],"names":["LRUCache","isStale","tagsManifest","memoryCache","entry","size","pendingSets","Map","debug","process","env","NEXT_PRIVATE_DEBUG_CACHE","console","bind","undefined","DefaultCacheHandler","get","cacheKey","pendingPromise","privateEntry","performance","timeOrigin","now","timestamp","revalidate","tags","returnStream","newSaved","vaLine truncated
+12
View File
@@ -0,0 +1,12 @@
/**
* A timestamp in milliseconds elapsed since the epoch
*/ /**
* This is a compatibility type to ease migration between cache handler
* versions. Until the old `CacheHandler` type is removed, this type should be
* used for all internal Next.js functions that deal with cache handlers to
* ensure that we are compatible with both cache handler versions. An exception
* is the built-in default cache handler, which implements the
* {@link CacheHandlerV2} interface.
*/ export { };
//# sourceMappingURL=types.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/cache-handlers/types.ts"],"sourcesContent":["/**\n * A timestamp in milliseconds elapsed since the epoch\n */\nexport type Timestamp = number\n\nexport interface CacheEntry {\n /**\n * The ReadableStream can error and only have partial data so any cache\n * handlers need to handle this case and decide to keep the partial cache\n * around or not.\n */\n value: ReadableStream<Uint8Array>\n\n /**\n * The tags configured for the entry excluding soft tags\n */\n tags: string[]\n\n /**\n * This is for the client, not used to calculate cache entry expiration\n * [duration in seconds]\n */\n stale: number\n\n /**\n * When the cache entry was created [timestamp in milliseconds]\n */\n timestamp: Timestamp\n\n /**\n * How long the entry is allowed to be used (should be longer than revalidate)\n * [duration in seconds]\n */\n expire: number\n\n /**\n * How long until the entry should be revalidated [duration in seconds]\n */\n revalidate: number\n}\n\n/**\n * @deprecated Use {@link CacheHandlerV2} instead.\n */\nexport interface CacheHandler {\n /**\n * Retrieve a cache entry for the given cache key, if available. The softTags\n * should be used to check for staleness.\n */\n get(cacheKey: string, softTags: string[]): Promise<undefined | CacheEntry>\n\n /**\n * Store a cache entry for the given cache key. When this is called, the entry\n * may still be pending, i.e. its value stream may still be written to. So it\n * needs to be awaited first. If a `get` for the same cache key is called\n * before the pending entry is complete, the cache handler must wait for the\n * `set` operation to finish, before returning the entry, instead of returning\n * undefined.\n */\n set(cacheKey: string, entry: Promise<CacheEntry>): Promise<void>\n\n /**\n * Next.js will call this method when `revalidateTag` or `revalidatePath()` is\n * called. It should update the tags manifest accordingly.\n */\n expireTags(...tags: string[]): Promise<void>\n\n /**\n * The `receiveExpiredTags` method is called when an action request sends the\n * 'x-next-revalidated-tags' header to indicate which tags have been expired\n * by the action. The local tags manifest should be updated accordingly. As\n * opposed to `expireTags`, the tags don't need to be propagated to a tags\n * service, as this was already done by the server action.\n */\n receiveExpiredTags(...tags: string[]): Promise<void>\n}\n\nexport interface CacheHandlerV2 {\n /**\n * Retrieve a cache entry for the given cache key, if available.\n */\n get(cacheKey: string): Promise<undefined | CacheEntry>\n\n /**\n * Store a cache entry for the given cache key. When this is called, the entry\n * may still be pending, i.e. its value stream may still be written to. So it\n * needs to be awaited first. If a `get` for the same cache key is called\n * before the pending entry is complete, the cache handler must wait for the\n * `set` operation to finish, before returning the entry, instead of returning\n * undefined.\n */\n set(cacheKey: string, pendingEntry: Promise<CacheEntry>): Promise<void>\n\n /**\n * Next.js will call this method periodically, but always before starting a\n * new request. When working with a remote tags service, this method should\n * communicate with the tags service to refresh the local tags manifest\n * accordingly.\n */\n refreshTags(): Promise<void>\n\n /**\n * Next.js will call this method for each set of soft tags that are relevant\n * at the start of a request. The result is the maximum timestamp of a\n * revalidate event for the tags. Returns `0` if none of the tags were ever\n * revalidated.\n */\n getExpiration(...tags: string[]): Promise<Timestamp>\n\n /**\n * Next.js will call this method when `revalidateTag` or `revalidatePath()` is\n * called. It should update the tags manifest accordingly.\n */\n expireTags(...tags: string[]): Promise<void>\n}\n\n/**\n * This is a compatibility type to ease migration between cache handler\n * versions. Until the old `CacheHandler` type is removed, this type should be\n * used for all internal Next.js functions that deal with cache handlers to\n * ensure that we are compatible with both cache handler versions. An exception\n * is the built-in default cache handler, which implements the\n * {@link CacheHandlerV2} interface.\n */\nexport type CacheHandlerCompat = CacheHandler | CacheHandlerV2\n"],"names":[],"mappings":"AAAA;;CAEC,GAkHD;;;;;;;CAOC,GACD,WAA8D"}