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

Make cache parameter optional when no caching is needed ! #91

Open
safizn opened this issue Feb 12, 2019 · 2 comments
Open

Make cache parameter optional when no caching is needed ! #91

safizn opened this issue Feb 12, 2019 · 2 comments
Labels
📕 cache Feature requests related to the cache project-apollo-client (legacy) LEGACY TAG DO NOT USE

Comments

@safizn
Copy link

safizn commented Feb 12, 2019

Hi, I chose to use apollo-client for my Nodejs build scripts, basically retrieving the latest release from a Github repository and pushing new releases.
I like the architecture of the module where different concerns are separated and pluggable (network protocol, caching implementation, etc.), but I find it strange that caching is mandatory, while at the same time the policy option for no-cache is available. What about treating undefined apollo-client cache option as if no-cache policy is on ?

Current implementation:

import { ApolloClient } from 'apollo-client'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { HttpLink } from 'apollo-link-http'

const defaultOptions = {
  watchQuery: {
    fetchPolicy: 'no-cache',  // 🙀
    errorPolicy: 'ignore',
  },
  query: {
    fetchPolicy: 'no-cache',  // 🙀
    errorPolicy: 'all',
  },
  mutate: {
    errorPolicy: 'all'
  }
}

const client = new ApolloClient({
  link: new HttpLink(),
  cache: new InMemoryCache(),  // 🙀
  defaultOptions 
})

Suggested implementation:

import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'

const client = new ApolloClient({
  link: new HttpLink(),
  cache: null  // 👌will result in `no-cache` default options for both `query` and `watchQuery`.
})

Versions:

"apollo-cache-inmemory": "^1.4.2",
"apollo-client": "^2.4.12",
"apollo-link-http": "^1.5.11"
@nekojanai
Copy link

I hope this is still being considered, very much would like to have that option!

@oshalygin
Copy link

With "@apollo/client": "3.0.0-beta.41",, is there any way to turn the cache off? I've gone through the docs pretty diligently but there's no mechanism like there was with with boost. With boost, you weren't required to provide the cache property to ApolloClient and if you just omitted it entirely, the cache appeared to be skirted entirely.

Motivation
Working with a cache is non-trivial and not something that many development teams need to battle with when they do not have a strong requirement around request caching. Cache invalidation is a whole ordeal that adds substantial layers of complexity to this library that many development teams would like to avoid until they actually need caching.

I've encountered dozens of bugs with onComplete and notifyOnNetworkStatusChange: true that are all related to the cache.

Related Issues

apollographql/apollo-client#1419

I dont mind helping contribute back and put together a PR to disable it and add the appropriate documentation in Configuring the Cache, but before doing so I'd like to spark a conversation and see where the team is at and if there is anything WIP.

I'm not quite clear on why defaultOptions were collapsed to no longer include watchQuery, query, and mutation props? The current object is the following:

    possibleTypes?: PossibleTypesMap;
    typePolicies?: TypePolicies;

Reproducing
If you decide not to pass the cache property to ApolloClient the following errors come through.

image

ApolloClient.js?f82c:24 Uncaught Invariant Violation: To initialize Apollo Client, you must specify a 'cache' property in the options object.

@jerelmiller jerelmiller added project-apollo-client (legacy) LEGACY TAG DO NOT USE 📕 cache Feature requests related to the cache labels Apr 6, 2023
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 project-apollo-client (legacy) LEGACY TAG DO NOT USE
Projects
None yet
Development

No branches or pull requests

4 participants