Documentation ¶
Overview ¶
TODO: readme, etc
Index ¶
- type Disc
- func (d *Disc[K, V, PV]) Check(ctx context.Context, k K) (v V, fresh bool, err error)
- func (d *Disc[K, V, PV]) Get(ctx context.Context, k K) (v V, err error)
- func (d Disc[K, V, PV]) Invalidate(ctx context.Context, k K) error
- func (d *Disc[K, V, PV]) Refresh(ctx context.Context, k K) (v V, err error)
- type Float32
- type Float64
- type InMem
- func (im *InMem[K, V]) Cancel()
- func (im *InMem[K, V]) Check(ctx context.Context, k K) (v V, fresh bool, err error)
- func (im *InMem[K, V]) Expiration() time.Duration
- func (im *InMem[K, V]) Get(ctx context.Context, k K) (v V, err error)
- func (im *InMem[K, V]) Invalidate(_ context.Context, k K) error
- func (im *InMem[K, V]) Purge()
- func (im *InMem[K, V]) Refresh(ctx context.Context, k K) (V, error)
- type Int
- type Int16
- type Int32
- type Int64
- type Int8
- type Interface
- type Redis
- func (r *Redis[K, V, PV]) Check(ctx context.Context, k K) (v V, found bool, err error)
- func (r *Redis[K, V, PV]) Get(ctx context.Context, k K) (v V, err error)
- func (r *Redis[K, V, PV]) Invalidate(ctx context.Context, k K) error
- func (r *Redis[K, V, PV]) Refresh(ctx context.Context, k K) (v V, err error)
- type String
- type Uint
- type Uint16
- type Uint32
- type Uint64
- type Uint8
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Disc ¶
type Disc[K fmt.Stringer, V any, PV interface { encoding.BinaryMarshaler encoding.BinaryUnmarshaler *V }] struct { // contains filtered or unexported fields }
Disc is a cache which uses the host filesystem. It is safe for concurrent use WITHIN the same program, but not ACROSS programs. there's still some bugs to work out re: locking the host filesystem, especially across platforms. use at your own risk.
func (Disc[K, V, PV]) Invalidate ¶
type Float32 ¶
type Float32 float32
Float32 and Float64 are aliases for the primitives that implement fmt.Stringer, encoding.TextMarshaler (on *T), and encoding.Unmarshaler (on *T).
type Float64 ¶
type Float64 float64
Float32 and Float64 are aliases for the primitives that implement fmt.Stringer, encoding.TextMarshaler (on *T), and encoding.Unmarshaler (on *T).
type InMem ¶
type InMem[K, V any] struct { // contains filtered or unexported fields }
InMem is an expiring cache for a function where values are stored in memory. This is safe for concurrent use among any number of goroutines.
func NewInMem ¶
func NewInMem[K, V any]( f func(context.Context, K) (V, error), invalidateAfter, cleanupEvery time.Duration, ) *InMem[K, V]
NewInMem creates an expiring cache for a function where values are stored in memory.
func (*InMem[K, V]) Cancel ¶
func (im *InMem[K, V]) Cancel()
Cancel the cache, freeing up it's resources. It is undefined behavior to use the cache after cancellation.
func (*InMem[K, V]) Expiration ¶
func (*InMem[K, V]) Get ¶
Get the item by loading a fresh cache value, Refresh()-ing the cache if necessary.
func (*InMem[K, V]) Invalidate ¶
Invalidate the cached result for k. Never returns an error.
type Int ¶
type Int int
Int8..=Int64 are aliases for the primitives that implement fmt.Stringer, encoding.TextMarshaler, and encoding.Unmarshaler.
func (*Int) MarshalBinary ¶
MarshalBinary marshals the integer type as 8 bytes, little-endian, regardless of source size.
func (*Int) UnmarshalBinary ¶
Unmarshal.Binary unmarshals the integer from the first eight bytes, little-endian. THERE IS NO ERROR CHECKING WHATSOEVER.
func (*Int) UnmarshalText ¶
UnmarshalText via strconv.ParseUint.
type Int16 ¶
type Int16 int16
Int8..=Int64 are aliases for the primitives that implement fmt.Stringer, encoding.TextMarshaler, and encoding.Unmarshaler.
func (*Int16) MarshalBinary ¶
MarshalBinary marshals the integer type as 8 bytes, little-endian, regardless of source size.
func (*Int16) MarshalText ¶
MarshalText calls String().
func (*Int16) UnmarshalBinary ¶
Unmarshal.Binary unmarshals the integer from the first eight bytes, little-endian. THERE IS NO ERROR CHECKING WHATSOEVER.
func (*Int16) UnmarshalText ¶
type Int32 ¶
type Int32 int32
Int8..=Int64 are aliases for the primitives that implement fmt.Stringer, encoding.TextMarshaler, and encoding.Unmarshaler.
func (*Int32) MarshalBinary ¶
MarshalBinary marshals the integer type as 8 bytes, little-endian, regardless of source size.
func (*Int32) MarshalText ¶
MarshalText calls String().
func (*Int32) UnmarshalBinary ¶
Unmarshal.Binary unmarshals the integer from the first eight bytes, little-endian. THERE IS NO ERROR CHECKING WHATSOEVER.
func (*Int32) UnmarshalText ¶
UnmarshalText via strconv.ParseInt.
type Int64 ¶
type Int64 int64
Int8..=Int64 are aliases for the primitives that implement fmt.Stringer, encoding.TextMarshaler, and encoding.Unmarshaler.
func (*Int64) MarshalBinary ¶
MarshalBinary marshals the integer type as 8 bytes, little-endian, regardless of source size.
func (*Int64) MarshalText ¶
MarshalText calls String().
func (*Int64) UnmarshalBinary ¶
Unmarshal.Binary unmarshals the integer from the first eight bytes, little-endian. THERE IS NO ERROR CHECKING WHATSOEVER.
func (*Int64) UnmarshalText ¶
UnmarshalText via strconv.ParseInt.
type Int8 ¶
type Int8 int8
Int8..=Int64 are aliases for the primitives that implement fmt.Stringer, encoding.TextMarshaler, and encoding.Unmarshaler.
func (*Int8) MarshalBinary ¶
MarshalBinary marshals the integer type as 8 bytes, little-endian, regardless of source size.
func (*Int8) UnmarshalBinary ¶
Unmarshal.Binary unmarshals the integer from the first eight bytes, little-endian. THERE IS NO ERROR CHECKING WHATSOEVER.
func (*Int8) UnmarshalText ¶
UnmarshalText via strconv.ParseUint.
type Interface ¶
type Interface[K, V any] interface { // Invalidate the cached result for K. Invalidate(context.Context, K) error // Check the cache for a result without refreshing it. Check(context.Context, K) (v V, fresh bool, err error) // Get the cached result for K, refreshing the cache if necessary. Get(context.Context, K) (V, error) // Refresh gets a fresh result and refreshes the cache. Refresh(context.Context, K) (V, error) }
Interface represents a cache of an underlying function. It's satisfied by InMem, Disk, and Redis.
type Redis ¶
type Redis[K fmt.Stringer, V any, PV interface { encoding.TextMarshaler encoding.TextUnmarshaler *V }] struct { // contains filtered or unexported fields }
Redis is an expiring cache for a function where values are stored in a redis instance. This is safe for concurrent use among multiple programs & goroutines.
func NewRedis ¶
func NewRedis[K fmt.Stringer, V any, PV interface { encoding.TextMarshaler encoding.TextUnmarshaler *V }]( redis *redis.Client, expiresAfter time.Duration, f func(context.Context, K) (V, error), ) Redis[K, V, PV]
NewRedis builds a cache that
func (*Redis[K, V, PV]) Invalidate ¶
type String ¶
type String string
String is an alias for the primitive string that implements fmt.Stringer.
type Uint ¶
type Uint uint
Unt8..=UInt64 are aliases for the primitives that implement fmt.Stringer, encoding.TextMarshaler, and encoding.Unmarshaler.
func (*Uint) MarshalBinary ¶
MarshalBinary marshals the integer type as 8 bytes, little-endian, regardless of source size.
func (*Uint) UnmarshalBinary ¶
Unmarshal.Binary unmarshals the integer from the first eight bytes, little-endian. THERE IS NO ERROR CHECKING WHATSOEVER.
type Uint16 ¶
type Uint16 uint16
Unt8..=UInt64 are aliases for the primitives that implement fmt.Stringer, encoding.TextMarshaler, and encoding.Unmarshaler.
func (*Uint16) MarshalBinary ¶
MarshalBinary marshals the integer type as 8 bytes, little-endian, regardless of source size.
func (*Uint16) UnmarshalBinary ¶
Unmarshal.Binary unmarshals the integer from the first eight bytes, little-endian. THERE IS NO ERROR CHECKING WHATSOEVER.
func (*Uint16) UnmarshalText ¶
UnmarshalText via strconv.ParseUint.
type Uint32 ¶
type Uint32 uint32
Unt8..=UInt64 are aliases for the primitives that implement fmt.Stringer, encoding.TextMarshaler, and encoding.Unmarshaler.
func (*Uint32) MarshalBinary ¶
MarshalBinary marshals the integer type as 8 bytes, little-endian, regardless of source size.
func (*Uint32) UnmarshalBinary ¶
Unmarshal.Binary unmarshals the integer from the first eight bytes, little-endian. THERE IS NO ERROR CHECKING WHATSOEVER.
func (*Uint32) UnmarshalText ¶
UnmarshalText via strconv.ParseUint.
type Uint64 ¶
type Uint64 uint64
Unt8..=UInt64 are aliases for the primitives that implement fmt.Stringer, encoding.TextMarshaler, and encoding.Unmarshaler.
func (*Uint64) MarshalBinary ¶
MarshalBinary marshals the integer type as 8 bytes, little-endian, regardless of source size.
func (*Uint64) UnmarshalBinary ¶
Unmarshal.Binary unmarshals the integer from the first eight bytes, little-endian. THERE IS NO ERROR CHECKING WHATSOEVER.
func (*Uint64) UnmarshalText ¶
UnmarshalText via strconv.ParseUint.
type Uint8 ¶
type Uint8 uint8
Unt8..=UInt64 are aliases for the primitives that implement fmt.Stringer, encoding.TextMarshaler, and encoding.Unmarshaler.
func (*Uint8) MarshalBinary ¶
MarshalBinary marshals the integer type as 8 bytes, little-endian, regardless of source size.
func (*Uint8) UnmarshalBinary ¶
Unmarshal.Binary unmarshals the integer from the first eight bytes, little-endian. THERE IS NO ERROR CHECKING WHATSOEVER.
func (*Uint8) UnmarshalText ¶
UnmarshalText via strconv.ParseUint.