Skip to content

docs: document AppSync per-item cache eviction (evictFromApiCache)#720

Merged
sid88in merged 1 commit into
masterfrom
docs/502-cache-item-eviction
Jun 1, 2026
Merged

docs: document AppSync per-item cache eviction (evictFromApiCache)#720
sid88in merged 1 commit into
masterfrom
docs/502-cache-item-eviction

Conversation

@sid88in

@sid88in sid88in commented Jun 1, 2026

Copy link
Copy Markdown
Owner

What

Document AWS AppSync's per-item cache eviction (evictFromApiCache) in doc/caching.md, with VTL and JavaScript examples.

Closes #502.

Why

#502 asks the plugin to "support cache eviction" (AWS item-eviction feature).

There's nothing for the plugin to implement: $extensions.evictFromApiCache(...) (VTL) / extensions.evictFromApiCache(...) (JS, from @aws-appsync/utils) is a runtime AppSync utility called from within a resolver's mapping template or JS code. It is not a CloudFormation/config property — AppSync evaluates it at request time. The plugin already passes resolver templates and JS code through to AppSync verbatim, and already supports the one prerequisite (per-resolver caching with keys). So eviction has effectively been usable all along; it just wasn't discoverable from the plugin's docs.

This PR closes that gap by adding an "Evicting items from the cache" section to the caching guide.

What's in it

A new section in doc/caching.md (between "Per resolver caching" and "Flushing the cache") that:

  • Explains eviction is a runtime feature, so no plugin-specific config is needed — you call it from a resolver.
  • Notes the two constraints from the AWS docs: it only works in mutation resolvers, and the eviction key map must match the cached resolver's keys in the same order.
  • Shows a cached query resolver in plugin config, then how to evict its entry from a mutation resolver with both a VTL response template and a JavaScript resolver.
  • Links to the AWS extensions / caching docs for the precise rules.

Out of scope (intentional)

No code change. There is no sensible plugin abstraction to add here — eviction is inherently per-resolver runtime logic that lives in the user's template/code, which the plugin already passes through. Whole-cache flushing already exists via the flush-cache command and is cross-referenced from the same page.

Testing

Docs-only; prettier --check doc/caching.md passes. No source/tests touched, so build / lint / test / test:e2e are unaffected. The VTL and JS snippets mirror AWS's own published examples.

Confidence

  • The mechanics (runtime utility, mutation-only, key-order matching, callable from request/response template or JS) are verified against the AWS AppSync extensions and caching documentation.
  • Not exercised against a live cached API from this environment; the examples follow AWS's documented usage.

Summary by CodeRabbit

  • Documentation
    • Added documentation on how to remove cached resolver entries from AppSync, including examples for VTL and JavaScript resolvers.

evictFromApiCache is a runtime AppSync extension called from within a
resolver's mapping template or JS code, not a config/CloudFormation
property — the plugin already passes templates/code through and already
supports per-resolver caching keys, so eviction works today. Document it
in the caching guide with VTL and JS examples, covering the mutation-only
and key-order constraints.

Closes #502
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a new documentation section to doc/caching.md explaining how to evict individual cached resolver entries using AppSync's evictFromApiCache runtime extension. The section covers mutation-only constraints, cache-key matching requirements, and provides practical VTL and JavaScript resolver examples.

Changes

Cache Eviction Documentation

Layer / File(s) Summary
Cache eviction documentation section
doc/caching.md
New subsection describing evictFromApiCache runtime extension usage in mutation resolvers, cache-key matching semantics, and code examples in both VTL and JavaScript showing how to construct and evict cached entries.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A cache grows large, but fear not the load,
For evict we shall, down documentation's road,
One entry at a time, no flush needed here,
With VTL and JavaScript, crystal clear! 🐰✨

🚥 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 accurately summarizes the main change: adding documentation for AppSync's per-item cache eviction feature (evictFromApiCache) to the caching documentation file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
  • Commit unit tests in branch docs/502-cache-item-eviction

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

@sid88in

sid88in commented Jun 1, 2026

Copy link
Copy Markdown
Owner Author

doc update. merging, low risk

@sid88in sid88in requested a review from AlexHladin June 1, 2026 02:27

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@doc/caching.md`:
- Around line 56-58: The VTL and JS eviction examples use "context.arguments.id"
but must include the leading $ to match caching.keys exactly; update the VTL
snippet that sets $keys (and any usage of $util.qr or
$extensions.evictFromApiCache) to use "$context.arguments.id" as the key name,
and likewise update the JS example to use '$context.arguments.id' so the
eviction keys exactly match the resolver cachingKeys strings.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 16e486be-ea79-48aa-856f-277640b51bd3

📥 Commits

Reviewing files that changed from the base of the PR and between d71c3b5 and f3a90ca.

📒 Files selected for processing (1)
  • doc/caching.md

Comment thread doc/caching.md
Comment on lines +56 to +58
#set($keys = {})
$util.qr($keys.put("context.arguments.id", $ctx.args.id))
$extensions.evictFromApiCache("Query", "getNote", $keys)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

AWS AppSync evictFromApiCache key name format - should the key map use the exact string from the resolver's caching keys configuration including dollar sign prefix?

💡 Result:

When using the evictFromApiCache extension in AWS AppSync, the keys in your mapping object must exactly match the strings defined in your resolver's cachingKeys configuration [1][2][3]. If your cachingKeys configuration includes the dollar sign prefix (e.g., "$context.arguments.id"), you must include that exact string as the key in the mapping object provided to the evictFromApiCache function [2][3]. Key requirements for successful cache eviction include: 1. Exact Match: The map keys must match the configuration exactly, including the dollar sign [2][3]. 2. Order: If you are using multiple caching keys, the entries must be added to the mapping object in the same order they are defined in the resolver's cachingKeys list [1][3][4]. 3. Mapping: Each value in your mapping object should be the actual value you wish to use to identify the specific cache entry (e.g., the specific ID or username) [1][3]. For example, if your caching configuration is: cachingKeys: ['$context.arguments.id'] Your eviction call should look like this: extensions.evictFromApiCache('Query', 'getNote', { '$context.arguments.id': ctx.args.id });

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail
# Show the relevant section around the reported lines
nl -ba doc/caching.md | sed -n '35,70p'

Repository: sid88in/serverless-appsync-plugin

Length of output: 120


🏁 Script executed:

#!/bin/bash
set -euo pipefail
awk 'NR>=35 && NR<=70 {printf "%d:%s\n", NR, $0}' doc/caching.md

Repository: sid88in/serverless-appsync-plugin

Length of output: 1258


Fix cache eviction key mapping to exactly match caching.keys (include the $ prefix).

doc/caching.md defines the caching key as '$context.arguments.id' (line 50), but the VTL eviction example uses "context.arguments.id" (line 57), and the JS example similarly uses 'context.arguments.id' (line 69). AppSync eviction keys must match the resolver’s cachingKeys strings exactly (including $), so the examples should use "$context.arguments.id" / '$context.arguments.id'.

🤖 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 `@doc/caching.md` around lines 56 - 58, The VTL and JS eviction examples use
"context.arguments.id" but must include the leading $ to match caching.keys
exactly; update the VTL snippet that sets $keys (and any usage of $util.qr or
$extensions.evictFromApiCache) to use "$context.arguments.id" as the key name,
and likewise update the JS example to use '$context.arguments.id' so the
eviction keys exactly match the resolver cachingKeys strings.

@sid88in sid88in self-assigned this Jun 1, 2026
@sid88in sid88in merged commit ee0fb83 into master Jun 1, 2026
6 checks passed
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.

[FEATURE] please support cache eviction

1 participant