Compare commits

...

7 Commits

Author SHA1 Message Date
jolheiser 22ba431f90
CI
continuous-integration/woodpecker the build failed Details
2021-10-08 16:19:52 -05:00
jolheiser 8181d1d911
Test plugin
continuous-integration/woodpecker the build was successful Details
Signed-off-by: jolheiser <john.olheiser@gmail.com>
2021-10-08 16:13:16 -05:00
jolheiser aa2ab87542
CI
continuous-integration/woodpecker the build failed Details
2021-10-08 16:12:29 -05:00
jolheiser 1b55553512
Clone
continuous-integration/woodpecker the build failed Details
Signed-off-by: jolheiser <john.olheiser@gmail.com>
2021-10-08 16:11:00 -05:00
jolheiser e6d25c4883
CI
continuous-integration/woodpecker the build was successful Details
2021-10-08 16:08:20 -05:00
jolheiser efa4c09883
CI 2021-10-08 16:01:38 -05:00
jolheiser b1161035be
Add cache purge
continuous-integration/woodpecker the build was successful Details
Signed-off-by: jolheiser <john.olheiser@gmail.com>
2021-10-08 15:59:03 -05:00
3 changed files with 13 additions and 24 deletions

View File

@ -1,3 +1,7 @@
clone:
git:
image: docker.io/a6543/test_git_plugin:latest
pipeline: pipeline:
compliance: compliance:
image: golang:1.17 image: golang:1.17

View File

@ -1,9 +0,0 @@
go test -benchmem -bench=.
goos: linux
goarch: amd64
pkg: go.jolheiser.com/overlay
cpu: Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz
BenchmarkCache-8 134959974 9.003 ns/op 0 B/op 0 allocs/op
BenchmarkNoCache-8 897212 1369 ns/op 280 B/op 4 allocs/op
PASS
ok go.jolheiser.com/overlay 3.360s

View File

@ -18,12 +18,17 @@ type FS struct {
cache map[string]bool cache map[string]bool
} }
// PurgeCache purges the cache
func (f *FS) PurgeCache() {
f.cache = make(map[string]bool)
}
func (f *FS) apn(name string) string { func (f *FS) apn(name string) string {
return path.Join(f.root, name) return path.Join(f.root, name)
} }
func (f *FS) exists(name string) bool { func (f *FS) exists(name string) bool {
if has, ok := f.cache[name]; ok && f.doCache { if has, ok := f.cache[name]; ok {
return has return has
} }
_, err := os.Stat(f.apn(name)) _, err := os.Stat(f.apn(name))
@ -63,10 +68,9 @@ type Option func(*FS) error
// New returns a new FS // New returns a new FS
func New(root string, fs fs.FS, opts ...Option) (*FS, error) { func New(root string, fs fs.FS, opts ...Option) (*FS, error) {
x := &FS{ x := &FS{
fs: fs, fs: fs,
root: root, root: root,
doCache: true, cache: make(map[string]bool),
cache: make(map[string]bool),
} }
for _, opt := range opts { for _, opt := range opts {
@ -94,13 +98,3 @@ func WithSub(sub string) Option {
return return
} }
} }
// WithCaching sets a caching mode for an FS
// Caching avoids subsequent os.Stat to determine if a file exists on disk
// See bench.txt for differences in usage
func WithCaching(doCache bool) Option {
return func(x *FS) error {
x.doCache = doCache
return nil
}
}