-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor virtual file cache to ensure generators only run once per sy…
…nc (#268) * package/budfs: make target generator absolute to the filesystem * rework cache to only run generators at most once per sync
- Loading branch information
1 parent
701c178
commit a017868
Showing
19 changed files
with
342 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package vcache | ||
|
||
import "github.com/livebud/bud/internal/virtual" | ||
|
||
var Discard Cache = discard{} | ||
|
||
type discard struct{} | ||
|
||
func (discard) Has(path string) (ok bool) { return false } | ||
func (discard) Get(path string) (entry virtual.Entry, ok bool) { return nil, false } | ||
func (discard) Set(path string, entry virtual.Entry) {} | ||
func (discard) Delete(path string) {} | ||
func (discard) Range(fn func(path string, entry virtual.Entry) bool) {} | ||
func (discard) Clear() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package vcache | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/livebud/bud/internal/virtual" | ||
) | ||
|
||
type Cache interface { | ||
Has(path string) (ok bool) | ||
Get(path string) (entry virtual.Entry, ok bool) | ||
Set(path string, entry virtual.Entry) | ||
Delete(path string) | ||
Range(fn func(path string, entry virtual.Entry) bool) | ||
Clear() | ||
} | ||
|
||
func New() Cache { | ||
return &memory{} | ||
} | ||
|
||
type memory struct { | ||
sm sync.Map | ||
} | ||
|
||
func (c *memory) Has(path string) (ok bool) { | ||
_, ok = c.sm.Load(path) | ||
return ok | ||
} | ||
|
||
func (c *memory) Set(path string, entry virtual.Entry) { | ||
c.sm.Store(path, entry) | ||
} | ||
|
||
func (c *memory) Get(path string) (entry virtual.Entry, ok bool) { | ||
value, ok := c.sm.Load(path) | ||
if !ok { | ||
return nil, false | ||
} | ||
entry, ok = value.(virtual.Entry) | ||
if !ok { | ||
return nil, false | ||
} | ||
return entry, ok | ||
} | ||
|
||
func (c *memory) Delete(path string) { | ||
c.sm.Delete(path) | ||
} | ||
|
||
func (c *memory) Range(fn func(path string, entry virtual.Entry) bool) { | ||
c.sm.Range(func(key, value interface{}) bool { | ||
path, ok := key.(string) | ||
if !ok { | ||
return true | ||
} | ||
entry, ok := value.(virtual.Entry) | ||
if !ok { | ||
return true | ||
} | ||
return fn(path, entry) | ||
}) | ||
} | ||
|
||
func (c *memory) Clear() { | ||
c.sm.Range(func(key, value interface{}) bool { | ||
c.sm.Delete(key) | ||
return true | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.