Skip to content
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

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

Open
4 tasks done
ira-kaundal opened this issue Nov 27, 2023 · 2 comments
Open
4 tasks done

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

ira-kaundal opened this issue Nov 27, 2023 · 2 comments
Labels
📕 cache Feature requests related to the cache

Comments

@ira-kaundal
Copy link

ira-kaundal commented Nov 27, 2023

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:

  • A descriptive title
  • A description of the problem you're trying to solve, including why you think this is a problem
  • An overview of the suggested solution
  • If the feature changes current behavior, reasons why your solution is better

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

@jerelmiller jerelmiller added the 📕 cache Feature requests related to the cache label Nov 27, 2023
@ira-kaundal
Copy link
Author

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

@jerelmiller
Copy link
Member

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:

  • We might consider calling this drop (similar to how Rust works)
  • We'd like this to work on the type level, which would run when a record is evicted from the cache via cache.evict(), or removed via cache.gc().
  • We'd like to think through whether a drop function makes sense at the field level since there are additional cases to consider. Would it run when updating a value because this would be considered "dropping" the old value? Would it run exclusively when the field is removed from the cache (e.g. returning DELETE from cache.modify()), etc. These are some things to think about :)

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📕 cache Feature requests related to the cache
Projects
None yet
Development

No branches or pull requests

2 participants