Skip to main content

Marshaler

This class is a struct that marshals and unmarshals cache values. It integrates with a cache interface and can optionally use protobuf for serialization.

Methods


Get()

@classmethod
def Get(
ctx: context.Context,
key: any,
returnObj: any
) - > any, error

Retrieves a value from the cache associated with the given key and unmarshals it into the provided return object. Callers use this to fetch cached data, which might involve I/O operations.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the operation, allowing for cancellation and timeouts.
keyanyThe key used to identify the cached value.
returnObjanyThe object into which the retrieved cached value will be unmarshaled.

Returns

TypeDescription
any, errorThe unmarshaled object if successful, and an error if the retrieval or unmarshaling fails.

Set()

@classmethod
def Set(
ctx: context.Context,
key: any,
object: any,
options: store.Option
) - > err error

Stores an object in the cache under the specified key, marshaling the object before storage. Callers use this to persist data in the cache, which might involve I/O operations.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the operation, allowing for cancellation and timeouts.
keyanyThe key under which the object will be stored in the cache.
objectanyThe object to be marshaled and stored in the cache.
optionsstore.OptionOptional settings for the cache operation, such as expiration time.

Returns

TypeDescription
err errorAn error if the marshaling or storage operation fails, otherwise nil.