ladda-js / ladda

JavaScript data fetching layer with caching
https://petercrona.gitbooks.io/ladda/content/
MIT License
112 stars 16 forks source link

Unexpected behavior when ttl set to 0 #6

Closed crcatala closed 7 years ago

crcatala commented 7 years ago

When setting ttl value to 0, was expecting requests to appear not to be cached at all since the ttl was very small. Looks like it's defaulting back to the 300 seconds. I admit this is a weird scenario to set to 0, since that would mean bypassing the the caching altogether which a user probably would not do.

https://github.com/petercrona/ladda/blob/2b937889bcf021cf374bdf9d565afad5841dd14e/src/decorator/read.js#L12

petercrona commented 7 years ago

Good catch and thanks for reporting. I fixed this together with a planned improvement. Rather than leaving it to the consumer (query-cache/entity-store) to decide what an undefined ttl (and other fields) means, I'm setting the defaults initially (in the builder):

Code: https://github.com/petercrona/ladda/blob/master/src/builder.js#L19 Test: https://github.com/petercrona/ladda/blob/master/src/builder.spec.js#L108

crcatala commented 7 years ago

@petercrona awesome, appreciate the work your doing on this. good stuff!