title: How can I specify maximum cache-time for any data matching a regex in apollo-client with InMemoryCache?
body: <p>Some fields coming from the graphql server will have the shape <code>short-lived-token-XYZ123</code>.  Ideally we wouldn't even have to know the field names ahead of time, as any code we write will live in a library.  How can I hook into the InMemoryCache or the ApolloClient object to set the cache time of fields with values matching a regex?  Causing them to poll at a set interval would be really ideal, but because polling is query-centric, I dont think that is possible at the field level.  Giving them a specific cache time would be enough. Is there a way to hook into the InMemoryCache with a function that gets called on every read?</p>
  <p>Another option would be to make these token strings a graphql type <code>Token</code> like</p>
  <pre><code>type Token {
      id: String
  }
  
  </code></pre>
  <p>and then in the client it might be possible to define a custom cache behavior for this type when initializing the cache like</p>
  <pre class="lang-js prettyprint-override"><code>new InMemoryCache({
    typePolicies: {
      Token: {
        fields: {
          id: {
            read(cachedVal) {
              if (cacheTimeElapsed){
                  return null
              } else {
                  return cachedVal
              }
             
            }
          }
        },
      },
    },
  </code></pre>
  <p>But Im also unclear HOW to bust the cache using the read function.  What do I return from the function to tell the cache that it is busted and needs to refetch?  These docs are...challenging.  If I could just call a function on every single read and do what I need to do, that would be ideal.</p>
  <p>These fields will also be annotated in the apollo-server with <code>@token</code>(for other reasons), and we could potentially hook in here to somehow tell the client to cache-bust these fields.  Not sure how, but it's another option.</p>