- With issues:
- Use the search tool before opening a new issue.
- Please provide source code and commit sha if you found a bug.
- Review existing issues and provide feedback or react to them.
Description
I read the source code and did not find the existence of cache. I wonder why there is no cache. Is it because the Web framework does not need cache? Similar to CPU L1 cache, memory TLB. Highly hit interface access cache is fast, no need to re-enter the dictionary tree traversal. Therefore, I have two ideas, one is to manually increase the cache, the other is to count the number of interfaces, given the interval to automatically update the cache. The code below is a demo of the first idea, and I'll fill it in if caching works. Hope to get your reply, thank you
How to reproduce
// gin.go
type Engine struct {
...
cachegin bool
cachetable map[string]bool
...
}
func (engine *Engine)SetCache(rpath string) {
if engine.cachegin {
if _, ok := engine.cachetable[rpath]; !ok {
engine.cachetable[rpath] = true
}else{
panic("The cache already exists")
}
}
}
func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
c := engine.pool.Get().(*Context)
...
if rPath := c.Request.URL.Path; _, ok := engine.cachetable[rPath]; ok {
Do(c)
}else{
engine.handleHTTPRequest(c)
}
engine.pool.Put(c)
}
Expectations
$ curl http://localhost:8201/hello/world
Hello world
Actual result
$ curl -i http://localhost:8201/hello/world
<YOUR RESULT>
Environment
- go version:
- gin version (or commit ref):
- operating system:
Comment From: bbdshow
if you want to use cache, middleware cache plugin are a good choice for you eg: https://github.com/gin-contrib/cache