package cache

import "golang.org/x/build/cmd/watchflakes/internal/cache"

Package cache implements a simple file-based cache.

Index

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

A Cache is a directory holding cached data.

func Create

func Create(name string) (*Cache, error)

Create returns a cache using the named subdirectory of the user's cache directory. For example, on macOS, Create("myprog") uses $HOME/Library/Caches/myprog. Create creates the directory if it does not already exist.

func Disabled

func Disabled() *Cache

Disabled returns a Cache that is always empty. Reads always return no result, and writes succeed but are discarded.

func (*Cache) Read

func (c *Cache) Read(name string) ([]byte, time.Time, error)

Read reads the file with the given name in the cache. It returns the file content, its last modification time, and any error encountered. If the file does not exist in the cache, Read returns nil, time.Time{}, nil.

func (*Cache) Write

func (c *Cache) Write(name string, data []byte) error

Write writes data to the file with the given name in the cache.

Source Files

cache.go

Version
v0.0.0-20250421191922-3619c213cff3 (latest)
Published
Apr 21, 2025
Platform
linux/amd64
Imports
5 packages
Last checked
3 months ago

Tools for package owners.