diff --git a/bench.txt b/bench.txt new file mode 100644 index 0000000000000000000000000000000000000000..ba8bf45cbfa8cbd3d7b828835e06ca87a31b1fac --- /dev/null +++ b/bench.txt @@ -0,0 +1,9 @@ +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 diff --git a/overlay.go b/overlay.go index 2c14fc35805bfe0b128a2d164e5beaafb71e28f2..512bf1c77ece17e9cc8deba0777e8c8ea60d8e10 100644 --- a/overlay.go +++ b/overlay.go @@ -18,17 +18,12 @@ doCache 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 { return path.Join(f.root, name) } func (f *FS) exists(name string) bool { - if has, ok := f.cache[name]; ok { + if has, ok := f.cache[name]; ok && f.doCache { return has } _, err := os.Stat(f.apn(name)) @@ -68,9 +63,10 @@ // New returns a new FS func New(root string, fs fs.FS, opts ...Option) (*FS, error) { 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 {