Giter VIP home page Giter VIP logo

Comments (11)

eneajaho avatar eneajaho commented on July 2, 2024 3

I am a bit confused, I configured mine like this:

image

but looking at my localstorage I can only see a few files from assets and two requests being cached. All the other requests are just not being cached.

Am I doing something wrong?

You need withInterceptorsFromDi() inside provideHttpClient()

from cashew.

shaharkazaz avatar shaharkazaz commented on July 2, 2024 1

@eneajaho You are welcome to open a PR 🙂

from cashew.

JeanMeche avatar JeanMeche commented on July 2, 2024 1

This is what I would recommend, as Joost stated on the angular/angular#51303, interceptors are sensitive to ordering. They should be registered in a single place.

from cashew.

eneajaho avatar eneajaho commented on July 2, 2024

Regarding registering the interceptor, I opened an issue in the Angular repo as currently there's no way to register an interceptor directly from the library if we use functional interceptors.

angular/angular#51303

from cashew.

eneajaho avatar eneajaho commented on July 2, 2024

@shaharkazaz
Will do, but after I get some more information about the interceptor registering part.

Maybe we can just fallback to tell the developer to register the interceptor themselves.

So, it would be sth like:

app.config.ts

providers: [
  provideHttpClient(withInterceptors([
    httpCacheInterceptor // --> This will be imported from cashew
  ])),
  provideHttpCache() // --> Register other providers. 
]

from cashew.

muuvmuuv avatar muuvmuuv commented on July 2, 2024

I think you can already use it like this:

export function provideHttp(): EnvironmentProviders[] {
  return [
    provideHttpClient(
      withInterceptors([
        logInterceptor,
        tokenInterceptor,
        metaInterceptor,
        errorInterceptor,
      ]),
      withXsrfConfiguration({
        cookieName: 'x-csrf-token',
        headerName: 'X-CSRF-Token',
      }),
      withFetch(),
    ),
    importProvidersFrom(
      HttpCacheInterceptorModule.forRoot({
        ttl: 1000 * 60 * 10,
        strategy: 'explicit',
      }),
    ),
    makeEnvironmentProviders(useHttpCacheLocalStorage),
  ]
}

from cashew.

JonasDev17 avatar JonasDev17 commented on July 2, 2024

I am a bit confused, I configured mine like this:

image

but looking at my localstorage I can only see a few files from assets and two requests being cached. All the other requests are just not being cached.

Am I doing something wrong?

from cashew.

JonasDev17 avatar JonasDev17 commented on July 2, 2024

I am a bit confused, I configured mine like this:
image
but looking at my localstorage I can only see a few files from assets and two requests being cached. All the other requests are just not being cached.
Am I doing something wrong?

You need withInterceptorsFromDi() inside provideHttpClient()

I tried that, but it does not make a difference.
This is what I see in my localstorage:

image

But it should cache a lot more requests.

from cashew.

JonasDev17 avatar JonasDev17 commented on July 2, 2024

I don't know what changed but its working now.... Thanks!

from cashew.

waltercruz avatar waltercruz commented on July 2, 2024

could someone provide a clear example on how to configure cashew when using standalone bootstrap? Thanks on advance!

from cashew.

muuvmuuv avatar muuvmuuv commented on July 2, 2024

Seems to work with withInterceptorsFromDi but my response headers are not existing and no longer HttpHeaders and therefore .get() does not work.

from cashew.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.