Cache on query string

Is it possible to cache, using safe methods mode, based on query string?
I mean, can I have two different caches for listen_path/api/?id=3 and listen_path/api/?ip=7?

Yes, the full path is used for the cache, adding a querystring parameter busts it and caches a sepreate entry for that new entry:

https://github.com/TykTechnologies/tyk/blob/master/middleware_redis_cache.go#L44

I’ve tried to use the followings:

  1. ?id={id}

  2. ?id=3

But when I call http://localhost:8080/listen_path/?id=3 I get:

2016/05/03 10:06:04 http: panic serving 127.0.0.1:43702: runtime error: invalid memory address or nil pointer dereference
goroutine 184 [running]:
net/http.(*conn).serve.func1(0xc820076b00)
	/usr/local/go/src/net/http/server.go:1389 +0xc1
panic(0xc55920, 0xc82000e070)
	/usr/local/go/src/runtime/panic.go:426 +0x4e9
regexp.(*Regexp).get(0x0, 0x1)
	/usr/local/go/src/regexp/regexp.go:203 +0x154
regexp.(*Regexp).doExecute(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc820a8ff84, 0xb, 0x0, 0x0, ...)
	/usr/local/go/src/regexp/exec.go:428 +0x4d
regexp.(*Regexp).MatchString(0x0, 0xc820a8ff84, 0xb, 0x1)
	/usr/local/go/src/regexp/regexp.go:411 +0x67
main.(*APISpec).IsURLAllowedAndIgnored(0xc8203aa000, 0xc820a8ff80, 0x3, 0xc820a8ff84, 0xb, 0xc8206f2f80, 0x0, 0x0, 0x0, 0x0, ...)
	/home/tyk/go/src/github.com/lonelycode/tyk/api_definition_manager.go:1001 +0x11e
main.(*APISpec).IsRequestValid(0xc8203aa000, 0xc820072b60, 0xb07000, 0x0, 0x0, 0x0, 0x0)
	/home/tyk/go/src/github.com/lonelycode/tyk/api_definition_manager.go:1213 +0x1a5
main.(*VersionCheck).ProcessRequest(0xc820b1e1a0, 0x7f383983f528, 0xc820111040, 0xc820072b60, 0x0, 0x0, 0x0, 0x0, 0xc820a7cea0)
	/home/tyk/go/src/github.com/lonelycode/tyk/middleware_version_check.go:42 +0x58
main.CreateMiddleware.func1.1(0x7f383983f528, 0xc820111040, 0xc820072b60)
	/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:44 +0x178
net/http.HandlerFunc.ServeHTTP(0xc820b0b440, 0x7f383983f528, 0xc820111040, 0xc820072b60)
	/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f383983f528, 0xc820111040, 0xc820072b60)
	/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:54 +0x26f
net/http.HandlerFunc.ServeHTTP(0xc820b0b480, 0x7f383983f528, 0xc820111040, 0xc820072b60)
	/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f383983f528, 0xc820111040, 0xc820072b60)
	/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:54 +0x26f
net/http.HandlerFunc.ServeHTTP(0xc820b0b4c0, 0x7f383983f528, 0xc820111040, 0xc820072b60)
	/usr/local/go/src/net/http/server.go:1618 +0x3a
github.com/gorilla/mux.(*Router).ServeHTTP(0xc820a79b30, 0x7f383983f528, 0xc820111040, 0xc820072b60)
	/home/tyk/go/src/github.com/gorilla/mux/mux.go:98 +0x29e
net/http.(*ServeMux).ServeHTTP(0xc820a8fe00, 0x7f383983f528, 0xc820111040, 0xc820072b60)
	/usr/local/go/src/net/http/server.go:1910 +0x17d
net/http.serverHandler.ServeHTTP(0xc82049d980, 0x7f383983f528, 0xc820111040, 0xc820072b60)
	/usr/local/go/src/net/http/server.go:2081 +0x19e
net/http.(*conn).serve(0xc820076b00)
	/usr/local/go/src/net/http/server.go:1472 +0xf2e
created by net/http.(*Server).Serve
	/usr/local/go/src/net/http/server.go:2137 +0x44e

Oh I see, that will not work, you will need a listen path, even if it is just root (in which case you need to remove trailing slash from target), so for example:

Target: http://httpbin.org
Listen Path: /

Then enable caching on all safe requests.