Exemple #1
0
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
}
Exemple #2
0
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
}