aws / aws/aws-appsync-community
Clearing PER_RESOLVER_CACHE using wildcards
- Dominant language
- HTML
- Stars
- 507
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
■ Overview
I'm trying to retrieve a list of regional information stored in DynamoDB using Amplify Gen2's data feature in TypeScript.
(I understand this isn't an Amplify community.)
```
project/amplify/data/resource.ts
const schema = a.schema({ Area: a.model({ area_name: a.string() }) })
```
This code retrieves the list of areas from the browser, but because the list is very large, it can't be retrieved in a single Query.
Therefore, I use loop processing with nextToken, repeating the process until there's no nextPageToken in the API response.
```
app/page.tsx
let areaList;
do {
areaList = await Area.list({ nextToken: nextPageToken });
} while(areaList.nextPageToken);
```
From here on, this is a general discussion:
For this listArea Query, I set $context.args as the cache key from the management console and set a TTL.
If 10 loops occur to retrieve this area list, I think PER_RESOLVER_CACHE will maintain about 10 caches using nextToken as the cache key.
■ Question
If a specific area record is updated, I need to flush all caches of listArea in the resolver.
Can I delete all listArea caches by using evictFromApiCache and specifying nextToken with a wildcard?
Or is there an easier way?
Since I can't solve this problem, I'm considering creating Lambda resolvers that retrieve all regional information at once and setting up caching for this resolver.
Contributor guide
Research direction
Start with project/amplify/data/resource.ts and app/page.tsx to understand how the Area.list query uses nextToken. Then investigate PER_RESOLVER_CACHE and evictFromApiCache, focusing on whether wildcard eviction can clear all listArea entries; done means establishing a supported cache-invalidation approach for updated area records.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, graphql, typescript
- Domain
- api, cloud, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100