GithubHelp home page GithubHelp logo

Comments (4)

lukechilds avatar lukechilds commented on August 22, 2024 2

Btw, I have actually been meaning to build a reverse proxy backed by cacheable-request but haven't had the time to put into it yet.

Let me know if you build it, I'd love to link to it in the readme.

from cacheable.

lukechilds avatar lukechilds commented on August 22, 2024

It is suitable to be used a shared cache, private is not cacheable and s-maxage is respected.

I don't think nodejitsu/node-http-proxy supports passing in a request function so not with that lib directly but I'm sure there are others that do. If not it wouldn't be too simple to write your own, for example see:

https://github.com/lukechilds/pirateproxy (Got uses cacheable-request under the hood)

from cacheable.

mokkabonna avatar mokkabonna commented on August 22, 2024

My understanding is that there are two types of cache, shared and private (called user agent cache or single user cache)

https://github.com/kornelski/http-cache-semantics#constructor-options

If options.shared is true (default), then the response is evaluated from a perspective of a shared cache (i.e. private is not cacheable and s-maxage is respected). If options.shared is false, then the response is evaluated from a perspective of a single-user cache (i.e. private is cacheable and s-maxage is ignored).

And MDN:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Cacheability

private
Indicates that the response is intended for a single user and must not be stored by a shared cache. A private cache may store the response.

Anyway by diving into this library code, I can see that it is using the default options of http-cache-semantics which has shared cache set to true. So it will not cache any response that have cache-control: private

It would be nice if we could set all or some of the cachepolicy options ourselves. I am implementing a user agent and would benefit from caching responses with cache-control: private

PR wanted?

from cacheable.

lukechilds avatar lukechilds commented on August 22, 2024

Sorry, just seen this, yeah definitely, it should be very simple to change.

For example:

response.cachePolicy = new CachePolicy(opts, response);

Just needs to be:

response.cachePolicy = new CachePolicy(opts, response, opts.cachePolicy);

(or similar)

And then you have full control over the CachePolicy options.

from cacheable.

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.