Skip to content

fix: bust greeting audio cache on template PUT and DELETE#757

Open
priyanshi-2003 wants to merge 1 commit into
juspay:releasefrom
priyanshi-2003:fix/bust-greeting-cache-on-template-update
Open

fix: bust greeting audio cache on template PUT and DELETE#757
priyanshi-2003 wants to merge 1 commit into
juspay:releasefrom
priyanshi-2003:fix/bust-greeting-cache-on-template-update

Conversation

@priyanshi-2003
Copy link
Copy Markdown
Contributor

@priyanshi-2003 priyanshi-2003 commented May 12, 2026

invalidate_template() only deletes the template model cache key (bb:template:{id}) but the pre-synthesized greeting audio is stored under a separate key (greeting:template:{id}). After a PUT, the old audio was still being served from Redis causing initial_greeting changes to have no effect until TTL expiry.

  • Delete greeting:template:{id} in both PUT and DELETE handlers
  • Add get_redis_service import to handlers.py

Summary by CodeRabbit

  • Bug Fixes
    • Improved cache handling for greeting templates to ensure updates and deletions are reflected promptly in the application.

Review Change Stack

Copilot AI review requested due to automatic review settings May 12, 2026 07:35
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 914a1037-879b-4eb0-8752-274661d572c1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR adds direct Redis cache invalidation for greeting template cache entries. When a template is replaced or deleted, the handlers now explicitly delete the greeting:template:{template_id} key from Redis after the existing invalidation call, with logging to track the cache bust operation.

Changes

Greeting Template Cache Invalidation

Layer / File(s) Summary
Redis cache invalidation in template handlers
app/api/routers/breeze_buddy/templates/handlers.py
Import get_redis_service and add explicit Redis deletion of greeting:template:{template_id} cache keys in template replacement and deletion handlers' best-effort invalidation blocks, with log messages.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

A greeting cached, now fades away,
When templates change or melt to gray—
Redis whispers delete's song,
Freshness flows where stale was long! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing cache invalidation for greeting audio in Redis across template PUT and DELETE operations.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

invalidate_template() only deletes the template model cache key
(bb:template:{id}) but the pre-synthesized greeting audio is stored
under a separate key (greeting:template:{id}). After a PUT, the old
audio was still being served from Redis causing initial_greeting
changes to have no effect until TTL expiry.

- Delete greeting:template:{id} in both PUT and DELETE handlers
- Add get_redis_service import to handlers.py
@priyanshi-2003 priyanshi-2003 force-pushed the fix/bust-greeting-cache-on-template-update branch from 69c0186 to 247b2f0 Compare May 12, 2026 07:38
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/api/routers/breeze_buddy/templates/handlers.py`:
- Around line 495-497: The three-line Redis cache invalidation repeated in
replace_template_handler and delete_template_handler should be extracted into a
module-level async helper named e.g. invalidate_greeting_cache(template_id: str)
that calls get_redis_service(), performs
redis.delete(f"greeting:template:{template_id}") and logs via logger.info;
replace the duplicated blocks in both replace_template_handler and
delete_template_handler with a call to invalidate_greeting_cache(template_id) so
all Redis cache logic is centralized and maintainable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aa4eedf8-8d1e-482e-95fd-9df29fe5955a

📥 Commits

Reviewing files that changed from the base of the PR and between 842c411 and 69c0186.

📒 Files selected for processing (1)
  • app/api/routers/breeze_buddy/templates/handlers.py

Comment on lines +495 to +497
redis = await get_redis_service()
await redis.delete(f"greeting:template:{template_id}")
logger.info(f"Greeting cache busted for template: {template_id}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Extract duplicate cache invalidation logic into a helper function.

The same 3-line greeting cache invalidation block appears in both replace_template_handler and delete_template_handler. This violates the DRY principle and makes the code harder to maintain.

♻️ Proposed refactor to eliminate duplication

Add a helper function at the module level:

async def invalidate_greeting_cache(template_id: str) -> None:
    """
    Invalidate greeting audio cache for a template.
    
    Args:
        template_id: Template UUID
        
    Raises:
        Exception: Any Redis-related errors (caller should handle)
    """
    redis = await get_redis_service()
    await redis.delete(f"greeting:template:{template_id}")
    logger.info(f"Greeting cache busted for template: {template_id}")

Then in both handlers, replace the duplicate blocks with:

         try:
             await invalidate_template(template_id)
-            redis = await get_redis_service()
-            await redis.delete(f"greeting:template:{template_id}")
-            logger.info(f"Greeting cache busted for template: {template_id}")
+            await invalidate_greeting_cache(template_id)
         except Exception as cache_exc:

Also applies to: 589-591

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/api/routers/breeze_buddy/templates/handlers.py` around lines 495 - 497,
The three-line Redis cache invalidation repeated in replace_template_handler and
delete_template_handler should be extracted into a module-level async helper
named e.g. invalidate_greeting_cache(template_id: str) that calls
get_redis_service(), performs redis.delete(f"greeting:template:{template_id}")
and logs via logger.info; replace the duplicated blocks in both
replace_template_handler and delete_template_handler with a call to
invalidate_greeting_cache(template_id) so all Redis cache logic is centralized
and maintainable.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes stale Breeze Buddy initial greeting audio after template updates/deletes by also invalidating the Redis key used for pre-synthesized greeting audio (greeting:template:{id}), not just the template model cache key.

Changes:

  • On template PUT, delete greeting:template:{template_id} after calling invalidate_template().
  • On template DELETE, delete greeting:template:{template_id} after calling invalidate_template().
  • Import get_redis_service to perform the Redis deletion.
Comments suppressed due to low confidence (2)

app/api/routers/breeze_buddy/templates/handlers.py:501

  • The warning log message in this cache-bust block says "Template cache invalidation failed" but failures here could come from greeting-key deletion as well. Consider either splitting the operations/logging or updating the message so it accurately reflects which cache key failed to invalidate.
            await invalidate_template(template_id)
            redis = await get_redis_service()
            await redis.delete(f"greeting:template:{template_id}")
            logger.info(f"Greeting cache busted for template: {template_id}")
        except Exception as cache_exc:
            logger.warning(
                f"Template cache invalidation failed for {template_id}: {cache_exc}"
            )

app/api/routers/breeze_buddy/templates/handlers.py:595

  • Same as above: the warning message refers only to template cache invalidation, but this try-block now also deletes the greeting cache key. Adjust logging/structure so failures are attributable to the specific cache key that failed to invalidate.
        try:
            await invalidate_template(template_id)
            redis = await get_redis_service()
            await redis.delete(f"greeting:template:{template_id}")
            logger.info(f"Greeting cache busted for template: {template_id}")
        except Exception as cache_exc:
            logger.warning(
                f"Template cache invalidation failed for {template_id}: {cache_exc}"
            )

Comment on lines +495 to +497
redis = await get_redis_service()
await redis.delete(f"greeting:template:{template_id}")
logger.info(f"Greeting cache busted for template: {template_id}")
Comment on lines +589 to +591
redis = await get_redis_service()
await redis.delete(f"greeting:template:{template_id}")
logger.info(f"Greeting cache busted for template: {template_id}")
@amreetkhuntia
Copy link
Copy Markdown
Contributor

check deprecation once

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants