Documentation
¶
Overview ¶
Package cachefs 实现了缓存文件系统
缓存文件系统用于在 http.FileSystem 默认实现需要优化 通过比较修改时间,缓存文件系统在Open和Read时如果没有修改,减少系统调用(具体是避免os.Open,(*os.File).Read)
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buf ¶
type Buf struct {
// contains filtered or unexported fields
}
Buf 循环缓存
type CacheFs ¶
type CacheFs struct {
// contains filtered or unexported fields
}
CacheFs 缓存文件系统
通过比较修改时间,在Open和Read时如果没有修改,减少系统调用(具体是避免os.Open,(*os.File).Read)
type HttpCacheFs ¶
type HttpCacheFs struct {
// contains filtered or unexported fields
}
HttpCacheFs Http缓存文件系统
Example ¶
path := "path"
http.Handle("/", http.FileServer(NewHttpCacheFs(path)))
Example (Onefile) ¶
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
path := "path"
fs := NewHttpCacheFs(path)
f, err := fs.Open("index.html")
if err != nil {
panic(err)
}
i, err := f.Stat()
if err != nil {
panic(err)
}
http.ServeContent(w, r, "index.html", i.ModTime(), f)
})
func NewHttpCacheFs ¶
func NewHttpCacheFs(path string) *HttpCacheFs
NewHttpCacheFs 创建NewHttpCacheFs
- path 是相对的路径 相当于 http.Dir
func (*HttpCacheFs) Open ¶
func (fs *HttpCacheFs) Open(name string) (http.File, error)
Open 实现 http.FileSystem 接口
Click to show internal directories.
Click to hide internal directories.