Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend authorization cache handlers #396

Merged
merged 5 commits into from
Aug 7, 2017
Merged

Backend authorization cache handlers #396

merged 5 commits into from
Aug 7, 2017

Conversation

mikz
Copy link
Contributor

@mikz mikz commented Aug 3, 2017

Extract how cache is treated based on the backend response into a module.
It allows extension by adding custom handlers like:

local cache_handler = require('backend.cache_handler')

function cache_handler.handlers.custom(cache, cached_key, response, ttl)
  cache:add(...)
  return true or false
end
  • strict is the original handler

    • it removes cached key on any non successful response
  • resilient is the new handler

    • stores response in cache only when it was not a server error

It also allows overriding proxy.shared_cache method to create custom cache instance for all proxies.
That can be useful when replacing local shared memory cache with something like redis.

TODO

  • integration test

@octobot
Copy link

octobot commented Aug 3, 2017

Spell Checker found issues

doc/parameters.md

Line Typo
3 APIcast v2 has a number of parameters co
3 ariables) that can modify the behavior of the gateway. The following
5 e that when deploying APIcast v2 with OpenShift, some of thee
15 Default: **stderr**
17 or more information. The file pathcan be either absolute, or relati
21 nfo
21 warn
46 Default: "apicast"
77 Values: a number > **60**
78 Default: 0
80 r. The value should be set to 0 or more than 60. For example,
80 ould be set to 0 or more than 60. For example, if `APICAST_CON
80 ONFIGURATION_CACHE` is set to 120, the gateway will reload the
80 eload the configuration every 2 minutes (120 seconds).
80 onfiguration every 2 minutes (120 seconds).
84 Default: "127.0.0.1"
86 ning Redis instance for OAuth 2.0 flow. REDIS_HOST parameter
90 Default: 6379
92 ning Redis instance for OAuth 2.0 flow. REDIS_PORT parameter
98 ning Redis instance for OAuth 2.0 flow. REDIS_URL parameter c
98 e used to set the full URI as DSN format like: `redis://PASSWOR
102 pty, the DNS resolver will be autodiscovered.
154 Setting it to particual version will make it not auto
166 tificate bundle generated by [export-builtin-trusted-certs](https://github.com/openresty

Generated by 🚫 Danger

@mikz mikz force-pushed the backend-unavailable branch from 97d64ff to 60402c6 Compare August 3, 2017 13:01
mikz added 4 commits August 4, 2017 09:16
on some systems it can't find it
so it does not conflict with any installed modules
fixup extracted backend handling test

extract backend cache handler into own file
@mikz mikz force-pushed the backend-unavailable branch from 57a3db3 to 1146fcd Compare August 4, 2017 07:18
@mikz mikz requested a review from mayorova August 4, 2017 07:21
@mikz mikz changed the title [wip] options to handle response when backend is unavailable Backend authorization cache handlers Aug 4, 2017
@mayorova
Copy link
Contributor

mayorova commented Aug 4, 2017

Haven't tried yet, but looks good.
How can proxy.shared_cache be overriden?..

@mikz
Copy link
Contributor Author

mikz commented Aug 4, 2017

@mayorova

proxy.shared_cache = function()
end

fix and simplify tests with cache handler

rename failure cache handler to resilient

don't duplicate writes to the cache

document how to configure backend cache handler
@mikz mikz force-pushed the backend-unavailable branch from 1146fcd to c581509 Compare August 4, 2017 12:36
@mikz mikz merged commit a41b3fb into master Aug 7, 2017
@mikz mikz deleted the backend-unavailable branch August 7, 2017 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants