auth/token_cache.rs

alphacode · src/alphacode_base/auth/token_cache.rs · rust · MIT
auth

Process-wide OAuth token cache keyed by file path with mtime/size invalidation and zero-copy Arc hits.

// Source: https://github.com/dragonked2/alphacode | License: MIT | Copyright 2025-2026 Ali Essam
// Provided via justclaw.it.com; keep this notice with the code.
//! Process-wide cache for OAuth token files.
//!
//! # Why
//!
//! Every provider request re-read its token file from disk: a `stat`, a
//! permission-hardening call, a file read, and a JSON parse. On the Gemini
//! and Antigravity paths that ran once per request, adding three to four
//! syscalls to a code path that otherwise spends its time on the network.
//!
//! The tokens themselves change rarely — only when the user logs in, when a
//! refresh happens, or when the token file is edited externally. The cache
//! below keeps the parsed value in memory and re-reads the file only when
//! the token is about to expire, when the 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key