Giter Club home page Giter Club logo

Comments (13)

cchance27 avatar cchance27 commented on July 21, 2024 1

@alxpettit sorry fixed :) Would have been cool to PR that in, if this projects accepting PRs or is active still. As I can definitely see the usefulness of an option like that, for instance i call out to an API and the http-cache tags are irrelevant to me as I don't really need more than 1 update per 24 hours, so being able to just say set my own TTL as an override, would be so much better.

I'm also considering maybe trying to write a redis backend as we tend to use redis for our other projects so being able to share caches between different tools that use reqwest would be cool.

from http-cache.

06chaynes avatar 06chaynes commented on July 21, 2024 1

Just merged this change into develop, it'll be part of the next release once I have a chance to finish a few other changes up. Thanks again!

from http-cache.

06chaynes avatar 06chaynes commented on July 21, 2024 1

Also added a docs page for the cache modes to hopefully explain them a bit better
https://http-cache.rs/book/cache-modes.html

from http-cache.

06chaynes avatar 06chaynes commented on July 21, 2024

ForceCache should return the object from cache should it exists, ignoring staleness, but return a network error should the object not exist.

What is the behavior you are experiencing?

Edit: Was thinking of OnlyIfCached, ForceCache would do a normal request should the object not exist in cache, apologies!

from http-cache.

06chaynes avatar 06chaynes commented on July 21, 2024

After checking more into this I did find I needed to adjust the test for the ForceCache mode to make sure the cached object would be stale upon retrieval from cache (994cd41), the test did pass though so things should be working as expected for that mode.

from http-cache.

cchance27 avatar cchance27 commented on July 21, 2024

i believe what she's looking for is a way to ignore the cache headers and just always cache the result of a request for a duration.... basically

let is_cacheable = middleware.is_method_get_head()
            && self.mode != CacheMode::NoStore
            && self.mode != CacheMode::Reload;

an escape hash for this like

let is_cacheable = self.mode == CacheMode::AlwaysCache || (middleware.is_method_get_head()
            && self.mode != CacheMode::NoStore
            && self.mode != CacheMode::Reload);

which i don't think is possible currently?

from http-cache.

alxpettit avatar alxpettit commented on July 21, 2024

@cchance27

She/her please, but yes, I recall having trouble with this. For the project I was working on, I ended up refactoring to use my own crude URL-addressable cache logic in that project, but I can probably still dig up the experimental branch if need be.

from http-cache.

06chaynes avatar 06chaynes commented on July 21, 2024

It's something I can look into on my free time (if that ever becomes a thing again), but I absolutely would be happy to consider any PRs to the project.

from http-cache.

06chaynes avatar 06chaynes commented on July 21, 2024

Welcoming any thoughts on what I've worked out so far on this matter. I have a branch with the changes made here if interested https://github.com/06chaynes/http-cache/blob/ignore-rules/http-cache/src/lib.rs#L294

Right now this adds a new variant to CacheMode called IgnoreRules. This should ignore the the checks that determine if a response can be cached (other than being a 200 status) and the check that determine staleness. This will assume that you are managing the expiry of the cache record somewhere else (such as the options for the cache manager you are using if provided or by interfacing with the cache in a more direct manner).

from http-cache.

06chaynes avatar 06chaynes commented on July 21, 2024

@cchance27 @alxpettit forgot to tag, curious if you have any input on this new mode before merging to develop.

from http-cache.

cchance27 avatar cchance27 commented on July 21, 2024

Sorry been bit busy with work, a cursory look I think it meets what I was expect originally to be supported, leaving the TTL to the backend for the storage makes sense i think, i'll try to find time to play with it but i don't see any reason it shouldn't be mergeable as doesn't appear to break any of the original workflows you were originally handling, and does give us that option to override the is_cacheable checking on 200 returns, which is great.

from http-cache.

alxpettit avatar alxpettit commented on July 21, 2024

@06chaynes Seems reasonable :)

from http-cache.

alxpettit avatar alxpettit commented on July 21, 2024

Thanks for implementing the suggestion! :D

from http-cache.

Related Issues (18)

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.