X Enterprises
fastify-xauth-jwks

getPayloadCacheStats

Return cache statistics for a registered path validator — size, enabled flag, and TTL.

getPayloadCacheStats

Return statistics about the in-memory JWT payload cache for a registered path validator. Useful for monitoring cache health and diagnosing unexpected re-verification behaviour.

Signature

fastify.xAuth.validators.<name>.getPayloadCacheStats(): {
  size: number;
  enabled: boolean;
  ttl: number;
}

Params

None.

Returns

An object with:

PropertyTypeDescription
sizenumberNumber of token entries currently in the cache.
enabledbooleanWhether payload caching is active for this path.
ttlnumberCache entry TTL in milliseconds.

Throws

Does not throw.

Examples

Basic — log cache stats on a health endpoint

fastify.get("/admin/health", async () => {
  const stats = fastify.xAuth.validators.admin.getPayloadCacheStats();

  return {
    status: "ok",
    authCache: stats,
    // { size: 42, enabled: true, ttl: 300000 }
  };
});

Realistic — expose stats for all registered paths

fastify.get("/internal/auth-stats", async () => {
  const stats = {};

  for (const [name, validator] of Object.entries(fastify.xAuth.validators)) {
    stats[name] = validator.getPayloadCacheStats();
  }

  return stats;
  // {
  //   admin:  { size: 12, enabled: true, ttl: 300000 },
  //   portal: { size: 87, enabled: true, ttl: 300000 },
  // }
});

See Also

  • clearPayloadCache — Flush the cache when roles change or a user logs out
  • verifyJWT — Manually verify a token outside the request lifecycle

AI Context

package: "@xenterprises/fastify-xauth-jwks"
method: fastify.xAuth.validators.<name>.getPayloadCacheStats()
use-when: Inspect the JWT payload cache size, TTL, and enabled status for monitoring
returns: { size: number, enabled: boolean, ttl: number }
Copyright © 2026