cheapcash/writer.go

36 lines
489 B
Go
Raw Normal View History

2021-11-16 04:56:33 +00:00
package cheapcash
import "os"
func (c *Cache) Write(key string, value []byte) error {
err := checkDir(sanitizePath(c.Path))
if err != nil {
return err
}
2021-11-16 05:20:12 +00:00
check, err := c.Exists(c.Path + key)
2021-11-16 04:56:33 +00:00
if err != nil {
return err
}
if check {
err = c.Delete(key)
if err != nil {
return err
}
}
file, err := os.Create(sanitizePath(c.Path + key))
if err != nil {
return err
}
defer file.Close()
_, err = file.Write(value)
if err != nil {
return err
}
return nil
}