dumb question about caching

45 views
Skip to first unread message

Frank Graffagnino

unread,
Mar 22, 2015, 7:54:04 PM3/22/15
to gopro...@googlegroups.com
so, I'm new to golang, and proxy servers in general.  I'm looking for a way to cache off results in a proxy server until someone hits an "offline" switch, at which point the proxy starts serving up the cached responses rather than going out to the web.

I see that this package allows the user to generate the response to the URL.  Are there any folks combining this with caching? Anything already set up to do this, or would i need to write the caching stuff myself?

Thanks for any help!

FG

Elazar Leibovich

unread,
Mar 23, 2015, 12:46:57 AM3/23/15
to Frank Graffagnino, gopro...@googlegroups.com
Hi,

I'd use something like https://godoc.org/github.com/golang/groupcache/lru combined with goproxy.

You'll have something like

if isOff.Get() {
    return req, nil
}
resp, ok := cache.Get(req)
if !ok {
    return req, nil
}
return req, resp

For switching on and off, you can accept regular HTTP requests with the proxy.NonproxyHandler, and set the global isOff atomic variable with it.

--
You received this message because you are subscribed to the Google Groups "goproxy-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to goproxy-dev...@googlegroups.com.
To post to this group, send email to gopro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/goproxy-dev/5e1510f4-a1c8-4a8d-aba9-2d88195fdcf9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages