Git Product home page Git Product logo

Comments (2)

Alorel avatar Alorel commented on August 22, 2024 1

Hey. The readme was copied from the original library and was largely unchanged.

The default cache function is defined as follows so your fallback would not work as shrinkRay.cache is undefined:

const shouldCache = opts.cache || function () { return true; };

And as for providing examples, I really don't see much of a point:

  1. Given how req + res are standard abbreviations for request + response and how the README uses those variable names, it's clear what data the function can work with.
  2. The caching criteria would vary wildly from application to application; we might end up confusing the user even more if they are unable to get past the previous point.

A working version of the example you gave would look like this in its simplest form:

function shouldCache(req) {
   return req.url.startsWith('/static');
}

from shrink-ray.

Enalmada avatar Enalmada commented on August 22, 2024 1

Part of the confusion was my fault, I was unsure that if I didn't fall back to standard cache function I would cache files without etag or something equivalently bad. I was afraid my function would override some desired behavior but with your response and a more careful reading of the docs I see that I can return true from my override cache function without fear:

shrink-ray ... will never cache a response that does not include an ETag, even if the cache function returns true.

Phew. Thanks for your help!

from shrink-ray.

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.