示例#1
0
文件: cfile.go 项目: stvvan/golibs
func Read(fn string) (string, error) {
	if cacheInit == false {
		cacheInit = true
		fileCache = cache.New2(15*time.Minute, 1*time.Minute, cacheWorker)
	}
	var err error
	var data string
	fn, err = file.GetAbsolutePath(fn)
	if err != nil {
		return "", err
	}
	if xdata := fileCache.Get(fn); xdata == nil {
		if data, err = file.Read(fn); err != nil {
			return "", err
		}
		fileCache.Set(fn, data)
	} else {
		data = fmt.Sprint(xdata)
	}
	return data, nil
}
示例#2
0
文件: cfile.go 项目: stvvan/golibs
func Write(fn, str string, append bool) error {
	if cacheInit == false {
		cacheInit = true
		fileCache = cache.New2(15*time.Minute, 1*time.Minute, cacheWorker)
	}
	var err error
	var data string
	fn, err = file.GetAbsolutePath(fn)
	if err != nil {
		return err
	}
	if append {
		data, err = Read(fn)
		if err != nil {
			return err
		}
		fileCache.Set(fn, data+str)
	} else {
		fileCache.Set(fn, str)
	}
	return nil
}
示例#3
0
文件: cfile.go 项目: stvvan/golibs
func Reset() {
	fileCache = cache.New2(15*time.Minute, 1*time.Minute, cacheWorker)
	cacheInit = false
}