https://github.com/ancientlore/cachefs
Package cachefs implements a read-only cache around a fs.FS, using groupcache.
https://github.com/ancientlore/cachefs
Last synced: about 1 year ago
JSON representation
Package cachefs implements a read-only cache around a fs.FS, using groupcache.
- Host: GitHub
- URL: https://github.com/ancientlore/cachefs
- Owner: ancientlore
- License: other
- Created: 2022-08-28T20:35:06.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-06T22:05:23.000Z (over 1 year ago)
- Last Synced: 2025-04-09T10:33:50.597Z (about 1 year ago)
- Language: Go
- Size: 17.6 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cachefs
[](https://pkg.go.dev/github.com/ancientlore/cachefs)
Package `cachefs` implements a read-only cache around a `fs.FS`, using `groupcache`.
Using `cachefs` is straightforward:
// Setup groupcache (in this example with no peers)
groupcache.RegisterPeerPicker(func() groupcache.PeerPicker { return groupcache.NoPeers{} })
// Create the cached file system with group name "groupName", a 10MB cache, and a ten second expiration
cachedFileSystem := cachefs.New(os.DirFS("."), &cachefs.Config{GroupName: "groupName", SizeInBytes: 10*1024*1024, Duration: 10*time.Second})
// Use the file system as usual...
`cachefs` "wraps" the underlying file system with caching. You can specify groupcache parameters - the group name
and the cache size.
`groupcache` does not support expiration, but `cachefs` supports quantizing values so that expiration happens
around the expiration duration provided. Expiration can be disabled by specifying 0 for the duration.
See https://pkg.go.dev/github.com/golang/groupcache for more information on `groupcache`.