cache

package
v0.0.0-...-b1838e9 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAll

func AddAll[T HasDate](c Cache[T], responses []T) error

AddAll is a helper function to add a list of responses to a cache.

Types

type AppendOnly

type AppendOnly[T HasDate] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

AppendOnly is a thread-safe cache that allows appending new items.

func NewAppendCache

func NewAppendCache[T HasDate](r io.Reader, w io.Writer) (*AppendOnly[T], error)

NewAppendCache creates a new APODCache

func (*AppendOnly[T]) Add

func (c *AppendOnly[T]) Add(date string, response T) error

Add a single day to the cache

func (*AppendOnly[T]) Get

func (c *AppendOnly[T]) Get(date string) (T, bool)

Get a single day from the cache

func (*AppendOnly[T]) Has

func (c *AppendOnly[T]) Has(date string) bool

Has checks if a day is present in the cache

type Cache

type Cache[T any] interface {
	Add(string, T) error
	Get(string) (T, bool)
	Has(string) bool
}

Cache interface for caching generic types.

type Empty

type Empty[T any] struct{}

Empty cache that does nothing

func NewEmptyCache

func NewEmptyCache[T any]() *Empty[T]

NewEmptyCache creates a new EmptyCache

func (*Empty[T]) Add

func (c *Empty[T]) Add(date string, response T) error

Add a single day to the cache

func (*Empty[T]) Get

func (c *Empty[T]) Get(date string) (T, bool)

Get a single day from the cache

func (*Empty[T]) Has

func (c *Empty[T]) Has(date string) bool

Has checks if a date is in the cache

type FS

type FS interface {
	HasFile(name string) bool
	WriteFile(name string, data []byte) error
	ReadFile(name string) ([]byte, error)
}

FS is an interface that abstracts over types that behave like a file system. This includes both a local file system and a mock in-memory file system.

type FSCache

type FSCache[T any] struct {
	// contains filtered or unexported fields
}

FSCache is a cache that stores cached items in a "file system".

func NewFSCache

func NewFSCache[T any](
	fs FS,
	serializer func([]byte) (T, error),
	deserializer func(T) ([]byte, error),
) *FSCache[T]

NewFSCache creates a new FSCache.

func (*FSCache[T]) Add

func (c *FSCache[T]) Add(date string, response T) error

Add a single day to the cache.

func (*FSCache[T]) Get

func (c *FSCache[T]) Get(date string) (T, bool)

Get a single day from the cache.

func (*FSCache[T]) Has

func (c *FSCache[T]) Has(date string) bool

Has checks if a date is in the cache.

type HasDate

type HasDate interface {
	GetDate() string
}

HasDate is an interface for types that have a date based timestamp

type InMemoryFS

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

InMemoryFS is a file system that stores files in memory.

func NewInMemoryFS

func NewInMemoryFS() *InMemoryFS

NewInMemoryFS creates a new InMemoryFS.

func (*InMemoryFS) HasFile

func (fs *InMemoryFS) HasFile(name string) bool

HasFile checks if a file exists.

func (*InMemoryFS) ReadFile

func (fs *InMemoryFS) ReadFile(name string) ([]byte, error)

ReadFile reads data from a file.

func (*InMemoryFS) WriteFile

func (fs *InMemoryFS) WriteFile(name string, data []byte) error

WriteFile writes data to a file.

type LocalFS

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

LocalFS is a file system that interacts with the local file system through a base directory.

func NewLocalFS

func NewLocalFS(baseDir string) *LocalFS

NewLocalFS creates a new LocalFS.

func (*LocalFS) HasFile

func (fs *LocalFS) HasFile(name string) bool

HasFile checks if a file exists.

func (*LocalFS) ReadFile

func (fs *LocalFS) ReadFile(name string) ([]byte, error)

ReadFile reads data from a file.

func (*LocalFS) WriteFile

func (fs *LocalFS) WriteFile(name string, data []byte) error

WriteFile writes data to a file.

Jump to

Keyboard shortcuts

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