Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
Cache is a generic thread-safe cache that can be used to cache any type of data. It is used to cache data that is expensive to fetch, such as API responses. Cached data is stored in a JSON file, and is automatically expired after a certain amount of time (if lifetime is specified)
type Decoder ¶
type Decoder interface { // Decode decodes the given data and writes it to the given writer. Decode(r io.Reader, data any) error }
Decoder is an interface that wraps Decode method.
type Encoder ¶
type Encoder interface { // Encode encodes the given data and writes it to the given writer. Encode(w io.Writer, data any) error }
Encoder is an interface that wraps Encode method.
type FileSystem ¶
type Options ¶
type Options struct { // Path to the file to store the cache. // If not specified (empty string), the cache will be stored in memory. Path string // Lifetime is the time duration after which the cache expires. // Values below zero are treated as never expiring. // Defaults to -1. Lifetime time.Duration // FileSystem is a filesystem that is used to store the cache file. FileSystem FileSystem // Encoder is the encoder to use for the cache. Encoder Encoder // Decoder is the decoder to use for the cache. Decoder Decoder // ExpirationHook is a function that is called when the cache expires. ExpirationHook func() }
Options is a struct that contains options for the cache.
Click to show internal directories.
Click to hide internal directories.