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
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The context for the operation, allowing for cancellation and timeouts. |
| key | any | The key used to identify the cached value. |
| returnObj | any | The object into which the retrieved cached value will be unmarshaled. |
Returns
| Type | Description |
|---|---|
any, error | The 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
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The context for the operation, allowing for cancellation and timeouts. |
| key | any | The key under which the object will be stored in the cache. |
| object | any | The object to be marshaled and stored in the cache. |
| options | store.Option | Optional settings for the cache operation, such as expiration time. |
Returns
| Type | Description |
|---|---|
err error | An error if the marshaling or storage operation fails, otherwise nil. |