apollographql / apollo-feature-requests

πŸ§‘β€πŸš€ Apollo Client Feature Requests | (no πŸ› please).
Other
130 stars 7 forks source link

Support for a Cache type policy when field is Garbage Collected #411

Open ira-kaundal opened 1 year ago

ira-kaundal commented 1 year ago

Can we have the ability to register a type policy for what else we want to do when a field is Garbage collected?

For eg. If I am sending blobUrls in one of the object's fields, then when Garbage collection removes this object, can I also release the blob memory for this Url?

Proposed solution:

Let's say I have an Image object.

type Image {
 id: ID!
 blobUrl: string!
}

We add a type policy for what happens when the cached field is garbage collected:

const cache = new InMemoryCache({
  typePolicies: {
    Image: {
      fields: {
        blobUrl: {
          onGarbageCollected: (blobUrl) => URL.revokeObjectURL(blobUrl),
        },
      },
    },
  },
});

Feature requests should include as much detail as possible:

See here for more detail on what is expected of a feature request.

ira-kaundal commented 12 months ago

Hi @jerelmiller, just wanted to follow up on whether you have any thoughts on this proposal.

jerelmiller commented 12 months ago

Hey @ira-kaundal πŸ‘‹

We talked about this as a team yesterday and think this is an idea eventually worth pursuing! One of the other maintainers has toyed with an idea similar to this, so we think a feature like this makes sense.

A few notes on from our meeting on how we envision this feature:

These are just some preliminary ideas that evolve on your idea here which would need some additional design consideration, but again, definitely something that we think makes sense! We don't have a specific timeline we can guarantee yet since we are still planning out our next few versions.

Thanks for opening this request!