Giter Club home page Giter Club logo

Comments (11)

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

Just published new versions of the crates which should enable you to add the logic you desired, via new cache_bust field in the HttpCacheOptions struct.

from http-cache.

06chaynes avatar 06chaynes commented on July 21, 2024

By default when a request is made to an endpoint that is not GET or HEAD method it should delete the cache record for that endpoint should it exist, so I think that part should be covered unless I'm missing something. If you wanted to ignore the caching rules you could set the mode to IgnoreRules, which would ignore all the staleness logic and leave you in control of expiry.

As for the header based logic, I think you may be able to use a feature that was just added in PR #53 by @veeshi to accomplish this once a new release has been made. I think you could construct your client with a cache_mode_fn in HttpCacheOptions that handles the checks you need and changes the mode based on certain conditions.

I have the new feature merged into develop and hoping to have some time soon to cut a new release.

from http-cache.

marcodpt avatar marcodpt commented on July 21, 2024

My problem is that the database has triggers and related data, for example when inserting an item into an order, say POST /api/items, the GET /api/orders cache needs to be cleared too.

So any POST request in localhost:8000 should clear all endpoints cache associated with this origin (but not at localhost:9000)

This is my use case in a reverse proxy

from http-cache.

06chaynes avatar 06chaynes commented on July 21, 2024

Would it be possible for the logic that is making the request to interface with the cache manager directly? If so you could have it remove related records.

from http-cache.

marcodpt avatar marcodpt commented on July 21, 2024

I'll try, but anyway, thank you very much for your attention and your excellent work on this library.

from http-cache.

veeshi avatar veeshi commented on July 21, 2024

This caught me eye and it would be a useful feature to add support for a cache busting closure.

So the closure takes:

  • http::request::Parts
  • cache key closure, user provided one or the default if none provided.

It returns a list of keys for items to delete from the cache.

Users of the library can then either return, an empty list and no entries are deleted, or compute the default key or add additional keys and add matching logic based on the request.

from http-cache.

06chaynes avatar 06chaynes commented on July 21, 2024

This caught me eye and it would be a useful feature to add support for a cache busting closure.

So the closure takes:

  • http::request::Parts

  • cache key closure, user provided one or the default if none provided.

It returns a list of keys for items to delete from the cache.

Users of the library can then either return, an empty list and no entries are deleted, or compute the default key or add additional keys and add matching logic based on the request.

I think I can see how this might work but not sure exactly where it would bolt in, I'm open to exploring it though.

from http-cache.

veeshi avatar veeshi commented on July 21, 2024

I'll try putting together a PR if I get time this weekend to see what it could look like.

from http-cache.

veeshi avatar veeshi commented on July 21, 2024

I've jotted up an initial idea, it generates the keys to bust in the cache first and removes them before continuing with the actual request. Not sure if that is the ideal way to do it.

from http-cache.

marcodpt avatar marcodpt commented on July 21, 2024

Thank you very much, I'll try to write the cache and give you feedback, it will take a few days, but once I've done it I'll get back to you.

from http-cache.

06chaynes avatar 06chaynes commented on July 21, 2024

Sweet, looking forward to seeing how it turns out!

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.