36 lines
573 B
Go
36 lines
573 B
Go
|
package cachedb
|
||
|
|
||
|
import (
|
||
|
`os`
|
||
|
`path/filepath`
|
||
|
|
||
|
`r00t2.io/sysutils/paths`
|
||
|
)
|
||
|
|
||
|
/*
|
||
|
NewCache returns a Cache from path to SQLite file `db` (or ":memory:" for an in-memory one).
|
||
|
|
||
|
It will be created if it doesn't exist for persistent caches.
|
||
|
*/
|
||
|
func NewCache(db string) (c *Cache, err error) {
|
||
|
|
||
|
var exists bool
|
||
|
|
||
|
switch db {
|
||
|
case ":memory:":
|
||
|
default:
|
||
|
if exists, err = paths.RealPathExists(&db); err != nil {
|
||
|
return
|
||
|
}
|
||
|
if !exists {
|
||
|
if err = os.MkdirAll(filepath.Dir(db), 0700); err != nil {
|
||
|
return
|
||
|
}
|
||
|
if err = os.WriteFile()
|
||
|
}
|
||
|
}
|
||
|
// TODO
|
||
|
|
||
|
return
|
||
|
}
|