Documentation Index
Fetch the complete documentation index at: https://mintlify.com/santiagonieto09/portafolio/llms.txt
Use this file to discover all available pages before exploring further.
src/infrastructure/github/snapshot-cache.ts manages the dual-layer snapshot store. The module exports four functions used exclusively by github-api.server.ts.
Cache Configuration
| Constant | Value | Purpose |
|---|---|---|
WEEK_MS | 7 * 24 * 60 * 60 * 1000 (604 800 000 ms) | TTL for a fresh snapshot — 7 days |
CACHE_URL | 'https://portfolio.internal/snapshot' | Synthetic URL used as the Cloudflare Cache API lookup key |
memory = null and the module falls through to the Cloudflare Cache API. In Node.js / dev, the in-memory store persists for the lifetime of the process.
readSnapshot()
null if no valid
snapshot exists. The check order is:
- In-memory — if
memoryis set andDate.now() - memory.at < WEEK_MS, returnsmemory.valueimmediately without any I/O. - Cloudflare Cache API — calls
caches.default.match(CACHE_URL)and validates thex-snapshot-atresponse header against the same TTL. null— no fresh snapshot is available; the caller must re-fetch from GitHub.
memory is populated so subsequent
reads within the same isolate are served from memory.
readSnapshotOrStale()
readSnapshot() but also returns memory.value even if the
snapshot has expired. This is the last-resort path used when fetchPortfolio()
detects that the GitHub user endpoint is unreachable — it allows the site to serve
potentially outdated data rather than returning an error or empty state.
writeSnapshot(value)
- In-memory —
memoryis updated synchronously with the current timestamp. - Cloudflare Cache API — if available, stores the snapshot as a
Responseobject with the following headers:
| Header | Value |
|---|---|
content-type | application/json |
cache-control | public, max-age=604800 |
x-snapshot-at | Unix millisecond timestamp (used by readFromCacheApi to validate TTL) |
cache.put() call throws, the error is silently swallowed — the in-memory write is already committed.
invalidateSnapshot()
readSnapshot() call triggers a full re-fetch:
- Sets
memory = nullsynchronously. - Calls
caches.default.delete(CACHE_URL)— this is fire-and-forget (void … .catch(() => {})); the function returns before the deletion promise resolves.
invalidatePortfolioCache() in github-api.server.ts, which is itself
called at the start of every POST /api/public/sync request.
In development and Node.js environments,
globalThis.caches is undefined. All
functions that touch the Cloudflare Cache API check for its presence via
defaultCache() and silently skip the Cloudflare layer. Cache operations still
work end-to-end using the in-memory store only.