Coder Social home page Coder Social logo

Comments (8)

DianaIonita avatar DianaIonita commented on June 19, 2024

Hi @stoverlee,

When I specify request.path.querystring.param1 will it cache as just /test?

If you have settings like:

- http:
   path: /test
   method: get
   caching:
     enabled: true
     cacheKeyParameters:
       - name: request.querystring.param1

Then it will create a cache entry for all the different values it may receive of param1, i.e. one entry for /test?param1=A, another entry for /test?param1=B.
Yes, it includes the case when it's undefined, meaning when it's just /test.

If I use multivaluequerystring, will it cache all these 3 possibilities: /test?param1=test, /test?param2=test, /test?param1=test&param2=test?

You're right that the README needs to be updated. I need to add some of what's here - and also that multivaluequerystring is not supported. The plugin currently only supports cache key parameters coming from header, path and querystring. If you know of a way to define cache key parameters in the API Gateway console for multivaluequerystring, then there might also be a way to do it in code, but so far I've not been able to find out whether it's possible.

In your example, your parameters would be part of the querystring, so you'd only need to do this for it to create cache entries for all possiblities of param1 and param2:

- http:
   path: /test
   method: get
   caching:
     enabled: true
     cacheKeyParameters:
       - name: request.querystring.param1
       - name: request.querystring.param2

Multi-value query strings would look something like: /test?param=A&param=B, so param would be multi-valued: an array of A and B. The plugin doesn't currently support this, as I was mentioning above.

Is there a way to specify a catch all for querystring params, instead of explicitly specifying the params in multivaluequerystring? So I would want to cache on the url + querystringparams whatever the querystring parameters may be

I can only think of a way to have a catch-all for paths:

- http:
   path: /test/{proxy+}
   method: get
   caching:
     enabled: true
     cacheKeyParameters:
       - name: request.querystring.proxy

This would allow you to cache any paths to the right of /test/, so paths like:

  • /test/param1value/param2value
  • /test/some/path/here

In lambda code, you would have access to the path variable through the request.pathParameters.proxy and it would have the values param1value/param2value and some/path/here respectively, so you'd need to parse them.

However, this doesn't seem to work for query string parameters, so for the paths:

  • /test/some/path/here
    and
  • /test/some/path/here?query=123

the same cache entry would be created. request.pathParameters.proxy will always be some/path/here, regardless of query string. For a user, that would mean that no matter what they changed the query string to, they'd always get the page at /test/some/path/here.

Please let me know if it doesn't make sense.

Edit: I just noticed this PR on multivaluequerystring, I'll have a look at whether it's possible to add support.

Later edit: The PR was good, but didn't add support for multivaluequerystring.

from serverless-api-gateway-caching.

pavlelekic avatar pavlelekic commented on June 19, 2024

@DianaIonita Hello,
I also have a question on caching, is there a way to invalidate a certain route? Lets say api.domain.com/v2/users/47 route was cached, and I want to invalidate the cache only for that specific user 47 but not for all users. Is there a way to do that once the route was cached for that specific path parameter value? Thanks.

I imagine there is some kind of an endpoint like /invalidations where you can send the path and cache key parameters for which you want an invalidation to happen.

from serverless-api-gateway-caching.

DianaIonita avatar DianaIonita commented on June 19, 2024

Hi @pavlelekic,

Yes, you can invalidate specific cache keys by setting the header Cache-Control: max-age=0 in your request to api.domain.com/v2/users/47.

You might also need to configure per-key cache invalidation authorization with these plugin settings:

custom:
  apiGatewayCaching:
    enabled: true
    perKeyInvalidation:
      requireAuthorization: true # default is true
      handleUnauthorizedRequests: Fail # default is "IgnoreWithWarning".

from serverless-api-gateway-caching.

pavlelekic avatar pavlelekic commented on June 19, 2024

Thanks @DianaIonita!
Is there a way to flush the whole cache? Let’s say you deploy a new version of you application, and you want to flush the old cache (for all routes)?

from serverless-api-gateway-caching.

DianaIonita avatar DianaIonita commented on June 19, 2024

Hi @pavlelekic,

You can do that, for example, via the API Gateway console, in the Stage editor:

image

from serverless-api-gateway-caching.

pavlelekic avatar pavlelekic commented on June 19, 2024

Thanks!

from serverless-api-gateway-caching.

vvmspace avatar vvmspace commented on June 19, 2024

How to cache full query string?
I have a complex search and I want to cache it with a full querystring as a key

from serverless-api-gateway-caching.

DianaIonita avatar DianaIonita commented on June 19, 2024

Hi @vvmspace,
Apologies for the delay. You would use the query string as is as a cache key parameter, for example:

- http:
   path: /search
   method: get
   caching:
     enabled: true
     cacheKeyParameters:
       - name: request.querystring.searchParams

Please consider raising another issue if you'd like to have further discussions around this topic.

from serverless-api-gateway-caching.

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.