Skip to content

Tweak GC doc #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Writerside/topics/garbage-collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A field is considered stale if its **received date** is older than its (client c

See [](cache-control.md) for more information about staleness.

Stale fields can be removed from the cache by calling the `ApolloStore.removeStaleFields` function.
Stale fields can be removed from the cache by calling the [`ApolloStore.removeStaleFields()`](https://apollographql.github.io/apollo-kotlin-normalized-cache-incubating/kdoc/normalized-cache-incubating/com.apollographql.cache.normalized/remove-stale-fields.html) function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool! PS: would be cool to have an intelliJ plugin that does this automatically. There are a bunch of places where I could use this.


If all fields of a record are stale, the record itself is removed.

Expand All @@ -23,7 +23,7 @@ This can happen when:
- manually deleting records with [`ApolloStore.remove()`](https://apollographql.github.io/apollo-kotlin-normalized-cache-incubating/kdoc/normalized-cache-incubating/com.apollographql.cache.normalized/-apollo-store/remove.html)
- records get deleted because all their fields are [stale](#stale-fields)

Dangling references can be removed from the cache by calling the `ApolloStore.removeDanglingReferences` function.
Dangling references can be removed from the cache by calling the [`ApolloStore.removeDanglingReferences()`](https://apollographql.github.io/apollo-kotlin-normalized-cache-incubating/kdoc/normalized-cache-incubating/com.apollographql.cache.normalized/remove-dangling-references.html) function.

If all fields of a record are dangling references, the record itself is removed.

Expand All @@ -35,12 +35,13 @@ Note: if a field's value is a list for which one or more elements are dangling r
A record is **unreachable** if there exists no chain of references from the root record to it.

This can happen when:
- data that was previously returned by the server is no longer returned by a subsequent query
- manually adding records with [`ApolloStore.writeFragment()`](https://apollographql.github.io/apollo-kotlin-normalized-cache-incubating/kdoc/normalized-cache-incubating/com.apollographql.cache.normalized/-apollo-store/write-fragment.html)
- manually deleting records with [`ApolloStore.remove()`](https://apollographql.github.io/apollo-kotlin-normalized-cache-incubating/kdoc/normalized-cache-incubating/com.apollographql.cache.normalized/-apollo-store/remove.html) and `cascade = false`: the deleted record could be the only one referencing others
- references get deleted because they're [stale](#stale-fields)

Unreachable records can be removed from the cache by calling the `ApolloStore.removeUnreachableRecords` function.
Unreachable records can be removed from the cache by calling the [`ApolloStore.removeUnreachableRecords()`](https://apollographql.github.io/apollo-kotlin-normalized-cache-incubating/kdoc/normalized-cache-incubating/com.apollographql.cache.normalized/remove-unreachable-records.html) function.

## `ApolloStore.garbageCollect()`

The `ApolloStore.garbageCollect()` function is a convenience to remove all stale fields, dangling references, and unreachable records from the cache.
The [`ApolloStore.garbageCollect()`](https://apollographql.github.io/apollo-kotlin-normalized-cache-incubating/kdoc/normalized-cache-incubating/com.apollographql.cache.normalized/garbage-collect.html) function is a convenience to remove all stale fields, dangling references, and unreachable records from the cache.