MCPcopy Create free account
hub / github.com/plexdrive/plexdrive / NewCache

Function NewCache

drive/cache.go:51–80  ·  view source on GitHub ↗

NewCache creates a new cache instance

(cacheFile, configPath string, sqlDebug bool)

Source from the content-addressed store, hash-verified

49
50// NewCache creates a new cache instance
51func NewCache(cacheFile, configPath string, sqlDebug bool) (*Cache, error) {
52 Log.Debugf("Opening cache connection")
53
54 db, err := bolt.Open(cacheFile, 0600, nil)
55 if nil != err {
56 Log.Debugf("%v", err)
57 return nil, fmt.Errorf("Could not open cache file")
58 }
59
60 cache := Cache{
61 db: db,
62 tokenPath: filepath.Join(configPath, "token.json"),
63 }
64
65 // Make sure the necessary buckets exist
66 err = db.Update(func(tx *bolt.Tx) error {
67 if _, err := tx.CreateBucketIfNotExists(bObjects); nil != err {
68 return err
69 }
70 if _, err := tx.CreateBucketIfNotExists(bParents); nil != err {
71 return err
72 }
73 if _, err := tx.CreateBucketIfNotExists(bPageToken); nil != err {
74 return err
75 }
76 return nil
77 })
78
79 return &cache, err
80}
81
82// Close closes all handles
83func (c *Cache) Close() error {

Callers 1

mainFunction · 0.92

Calls 1

OpenMethod · 0.80

Tested by

no test coverage detected