filecache

package
v0.11.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

The filecache package provides a file-based shared durable blob cache.

The cache is a machine-global mapping from (kind string, key [32]byte) to []byte, where kind is an identifier describing the namespace or purpose (e.g. "analysis"), and key is a SHA-256 digest of the recipe of the value. (It need not be the digest of the value itself, so you can query the cache without knowing what value the recipe would produce.)

The space budget of the cache can be controlled by SetBudget. Cache entries may be evicted at any time or in any order. Note that "du -sh $GOPLSCACHE" may report a disk usage figure that is rather larger (e.g. 50%) than the budget because it rounds up partial disk blocks.

The Get and Set operations are concurrency-safe.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = fmt.Errorf("not found")

ErrNotFound is the distinguished error returned by Get when the key is not found.

Functions

func BugReports

func BugReports() (string, []bug.Bug)

BugReports returns a new unordered array of the contents of all cached bug reports produced by this executable. It also returns the location of the cache directory used by this process (or "" on initialization error).

func Get

func Get(kind string, key [32]byte) ([]byte, error)

Get retrieves from the cache and returns the value most recently supplied to Set(kind, key), possibly by another process. Get returns ErrNotFound if the value was not found.

Callers should not modify the returned array.

func Set

func Set(kind string, key [32]byte, value []byte) error

Set updates the value in the cache.

func SetBudget

func SetBudget(new int64) (old int64)

SetBudget sets a soft limit on disk usage of regular files in the cache (in bytes) and returns the previous value. Supplying a negative value queries the current value without changing it.

If two gopls processes have different budgets, the one with the lower budget will collect garbage more actively, but both will observe the effect.

Even in the steady state, the storage usage reported by the 'du' command may exceed the budget by as much as a factor of 3 due to the overheads of directories and the effects of block quantization, which are especially pronounced for the small index files.

func Start

func Start()

Start causes the filecache to initialize and start garbage gollection.

Start is automatically called by the first call to Get, but may be called explicitly to pre-initialize the cache.

Types

This section is empty.

Jump to

Keyboard shortcuts

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