X Enterprises
fastify-xauth-jwks

clearPayloadCache

Clear the in-memory JWT payload cache for a registered path validator.

clearPayloadCache

Clear all cached JWT payloads for a registered path validator. Subsequent requests will re-verify their tokens against JWKS instead of reading from the in-memory cache.

Useful when a user's roles or permissions change and you need to force re-verification immediately without waiting for the cache TTL to expire.

Signature

fastify.xAuth.validators.<name>.clearPayloadCache(): void

Params

None.

Returns

void

Throws

Does not throw.

Examples

Basic — clear cache after a role change

fastify.put("/admin/users/:id/roles", async (request, reply) => {
  const { roles } = request.body;

  await db.users.updateRoles(request.params.id, roles);

  // Force re-verification so the updated roles take effect immediately
  fastify.xAuth.validators.admin.clearPayloadCache();

  return { updated: true };
});

Realistic — clear cache on logout

fastify.post("/admin/logout", async (request, reply) => {
  const userId = request.auth.userId;

  await db.sessions.invalidate(userId);

  // Clear entire path cache — simpler than per-token eviction
  fastify.xAuth.validators.admin.clearPayloadCache();

  return reply.code(204).send();
});

See Also

AI Context

package: "@xenterprises/fastify-xauth-jwks"
method: fastify.xAuth.validators.<name>.clearPayloadCache()
use-when: Flush the in-memory JWT payload cache for a path — call after role/permission changes or forced logouts
returns: void
Copyright © 2026