Documentation
¶
Overview ¶
Package jsoncodec provides some helpful wrappers and a core Codec implementation to make using JSON payloads easy within systems using Galaxycache.
In general, it is recommended to use the github.com/vimeo/galaxycache/protocodec.CodecV2 codec if at all possible, as protobuf generally provides lower overhead in both space and proccessing-time, schemas that can evolve, and the ability to rename fields as necessary.
This package should *_not_* be used for caching protobuf message-types, it is *_always_* better to use binary marshaling with github.com/vimeo/galaxycache/protocodec.CodecV2 in that case.
Index ¶
- func BackendGetter[T any](f func(ctx context.Context, key string) (T, error)) galaxycache.BackendGetter
- func BackendGetterWithInfo[T any](f func(ctx context.Context, key string) (T, galaxycache.BackendGetInfo, error)) galaxycache.BackendGetterWithInfo
- func GalaxyGet[T any](ctx context.Context, g *galaxycache.Galaxy, key string) (m *T, getErr error)
- type Codec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BackendGetter ¶
func BackendGetter[T any](f func(ctx context.Context, key string) (T, error)) galaxycache.BackendGetter
BackendGetter is an adapter that implements galaxycache.BackendGetter (it wraps an unexported type because type-inference is much better on function-calls)
func BackendGetterWithInfo ¶ added in v1.4.0
func BackendGetterWithInfo[T any](f func(ctx context.Context, key string) (T, galaxycache.BackendGetInfo, error)) galaxycache.BackendGetterWithInfo
BackendGetterWithInfo is an adapter that implements galaxycache.BackendGetter (it wraps an unexported type because type-inference is much better on function-calls)
Types ¶
type Codec ¶
type Codec[T any] struct { // contains filtered or unexported fields }
Codec wraps another type, providing a simple wrapper for clients that want to wrap JSON.
Note: protocodec should generally be prefered for new deployments. This implementation is provided to provide an easy way to insert Galaxycache into systems that are already using JSON internally for the payloads they'll be working with.
func (*Codec[T]) Get ¶
func (c *Codec[T]) Get() *T
Get implies returns the internal protobuf message value
func (*Codec[T]) MarshalBinary ¶
MarshalBinary on a ProtoCodec returns the encoded proto message
func (*Codec[T]) Set ¶
func (c *Codec[T]) Set(v T)
Set bypasses Marshaling and lets you set the internal protobuf value
func (*Codec[T]) UnmarshalBinary ¶
UnmarshalBinary on a ProtoCodec unmarshals provided data into the proto message