Repository navigation
feat(api): caché de respuestas en Redis con invalidación (RNF-09) - #17
Merged
Merged
Conversation
Implementa caché de respuestas para preguntas repetidas usando Redis con TTL de 24h y cabecera X-Cache (HIT/MISS). - Añade módulo cache con cálculo determinista de clave hash SHA-256 (usuario, documentos consultados, pregunta normalizada y generación). - Implementa repositorio RedisResponseCache para almacenar y recuperar respuestas cacheadas e invalidar por generación de usuario. - Integra ResponseCache en ConversationService para responder desde caché omitiendo búsqueda vectorial y LLM en caso de HIT. - Invalida la caché del usuario incrementando la generación al subir o eliminar documentos en DocumentService. - Actualiza endpoint POST /conversations/:id/messages para propagar la cabecera X-Cache y tests unitarios, de contrato y de integración.
6 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resumen
POST /conversations/:id/messagesahora consulta Redis antes de buscar chunks o llamar al LLM: si hay hit, responde con la respuesta y citas cacheadas y seteaX-Cache: HITsin tocar embeddings/LLM (RNF-07, <300ms); si hay miss, sigue el camino normal y guarda el resultado en caché antes de persistir el mensaje.cache/utils/cache-key.ts, con tests exhaustivos (RNF-11 la nombra explícitamente como lógica de dominio a cubrir).INCR cache:gen:{userId}) en vez de borrado activo: subir o borrar un documento incrementa la generación, lo que cambia la clave de caché de la siguiente pregunta — las entradas viejas quedan huérfanas y expiran solas por el TTL de 24h, sin necesitarSCAN/KEYSbloqueante sobre Redis.Independiente de #16 en lógica de negocio; solo comparten
conversation.service.ts/conversation.routes.tsen puntos no adyacentes (verificado con merge de prueba local, sin conflictos).Test plan
pnpm --filter api typecheckpnpm --filter api lintpnpm --filter api test(252 passed)pnpm --filter api test:coverage(100% en services/schemas/utils, incluidacache-key.ts)pnpm --filter api test:integration(295 passed, Mongo real)🤖 Generated with Claude Code
https://claude.ai/code/session_01BoVKssKAe1Z1vGJAEBEzvy