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

Add HTTP Cache support to http_ng #357

Merged
merged 12 commits into from
May 5, 2017
Merged

Add HTTP Cache support to http_ng #357

merged 12 commits into from
May 5, 2017

Conversation

mikz
Copy link
Contributor

@mikz mikz commented Apr 27, 2017

Using Cache-Control: private the http client
should be able to cache responses and use the cache
on repeated calls

Good read: https://tools.ietf.org/html/rfc7234

You can use it like:

local cache_store = require('resty.http_ng.cache_store')
local resty_backend = require('resty.http_ng.backend.resty')
local cache_backend = require('resty.http_ng.backend.cache')

-- cache_backend.new(resty_backend) would use default cache store, but you can customise its size
local backend = cache_backend.new(resty_backend, { cache_store = cache_store.new(100) })
local http_client = http_ng.new({ backend = backend })

@mikz mikz changed the title add HTTP Cache support to http_ng [WIP] Add HTTP Cache support to http_ng Apr 27, 2017
@octobot
Copy link

octobot commented Apr 27, 2017

2 Warnings
⚠️ PR is classed as Work in Progress
⚠️ Big PR

Generated by 🚫 Danger

@mikz mikz self-assigned this May 3, 2017
@octobot octobot added the T-obux label May 3, 2017
@@ -87,7 +87,7 @@ http.method = function(method, client)
local req_params = get_request_params(method, client, url, options)
local req = http.request.new(req_params)

return client.backend.send(req)
return client.backend:send(req)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between : and . ?

Copy link
Contributor Author

@mikz mikz May 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah! : is syntactic sugar for passing self.

So these are the same code:

object:method(param)
object.method(object, param)

This works in the function definition too:

function _M.method(self, param)
end

function _M:method(param)
end

Passing self It is the only way how a function can know about the object being called on. Like instance method. Otherwise it does not really have any state other than a closure.

@mikz mikz requested review from hallelujah and macejmic May 4, 2017 16:21
@mikz mikz changed the title [WIP] Add HTTP Cache support to http_ng Add HTTP Cache support to http_ng May 4, 2017
@mikz mikz merged commit 4f981ce into master May 5, 2017
@mikz mikz deleted the http-cache branch May 5, 2017 05:12
@mikz mikz removed the in progress label May 5, 2017
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