cachefs

package module
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

README

cachefs

Go Reference

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.

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(innerFS fs.FS, config *Config) fs.FS

New creates a new cached FS around innerFS using groupcache with the given configuration. The returned FS is read-only. If config is nil, it defaults to a 1MB cache using a random GUID as a name.

Types

type Config

type Config struct {
	GroupName   string        // Name of the groupcache group
	SizeInBytes int64         // Size of the cache
	Duration    time.Duration // Duration after which items can expire
	NoStat      bool          // Don't do extra file Stat calls in ReadDir
}

Config stores the configuration settings of your cache.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL