diff --git a/cache_test.go b/cache_test.go index 0893892..3f29ea5 100644 --- a/cache_test.go +++ b/cache_test.go @@ -21,6 +21,9 @@ func ExampleCache() { cache.Set([]byte("user5"), 5) fmt.Println(cache.Get([]byte("user3"))) + cache.Set([]byte("user5"), 6) + fmt.Println(cache.Get([]byte("user5")).(int)) + cache2 := newCache(0) cache2.Set([]byte("user1"), 1) fmt.Println(cache2.Get([]byte("user1")).(int)) @@ -31,5 +34,6 @@ func ExampleCache() { // // 2 // + // 6 // 1 } diff --git a/router.go b/router.go index 6b428bd..0c5c0d8 100644 --- a/router.go +++ b/router.go @@ -400,9 +400,9 @@ func (gb *gearbox) matchRouteAgainstRegistered(method, path []byte) (handlersCha trimmedPath := trimPath(path) // Try to get from cache if it's enabled - cacheKey := "" + cacheKey := make([]byte, 0) if !gb.settings.DisableCaching { - cacheKey := append(method, trimmedPath...) + cacheKey = append(method, trimmedPath...) if cacheResult, ok := gb.cache.Get(cacheKey).(*matchParamsResult); ok { return cacheResult.Handlers, cacheResult.Params } diff --git a/router_test.go b/router_test.go index db5f0c7..6a73a2f 100644 --- a/router_test.go +++ b/router_test.go @@ -34,6 +34,7 @@ func TestValidateRoutePath(t *testing.T) { {input: []byte("/user/*"), isErr: false}, {input: []byte("/user/:name"), isErr: false}, {input: []byte("/user/:name/:name"), isErr: true}, + {input: []byte("/user/:name?/get"), isErr: true}, } for _, tt := range tests { @@ -294,7 +295,7 @@ func TestConstructRoutingTree(t *testing.T) { {method: []byte(MethodGet), path: []byte("/books/search/:pattern:([a-z]+)"), handler: emptyHandlersChain}, {method: []byte(MethodGet), path: []byte("/books/search/:pattern"), handler: emptyHandlersChain}, {method: []byte(MethodGet), path: []byte("/books/search/:pattern1/:pattern2/:pattern3"), handler: emptyHandlersChain}, - {method: []byte(MethodGet), path: []byte("/books/search/*"), handler: emptyHandlersChain}, + {method: []byte(MethodGet), path: []byte("/books//search/*"), handler: emptyHandlersChain}, {method: []byte(MethodGet), path: []byte("/account/:name?"), handler: emptyHandlersChain}, {method: []byte(MethodGet), path: []byte("/profile/:name:([a-z]+)?"), handler: emptyHandlersChain}, {method: []byte(MethodGet), path: []byte("/order/:name1/:name2:([a-z]+)?"), handler: emptyHandlersChain},