NamespacedCache
NamespacedCache is a wrapper around a cache that adds a namespace to all keys
Methods
getNamespacedKey()
@classmethod
def getNamespacedKey(
key: any
) - > string
Generates a namespaced key by prepending the cache's namespace to the provided key. This ensures uniqueness for keys within the NamespacedCache instance.
Parameters
| Name | Type | Description |
|---|---|---|
| key | any | The original key to be namespaced. |
Returns
| Type | Description |
|---|---|
string | The fully qualified namespaced key as a string. |
Get()
@classmethod
def Get(
ctx: context.Context,
key: any
) - > (T, error)
Retrieves an object from the cache using a namespaced key. This method delegates to the underlying cache's Get method after applying the namespace.
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The context for the operation, allowing for cancellation and deadlines. |
| key | any | The key associated with the object to retrieve from the cache. |
Returns
| Type | Description |
|---|---|
(T, error) | A tuple containing the retrieved object of type T and an error if the operation failed. |
Set()
@classmethod
def Set(
ctx: context.Context,
key: any,
object: T,
options: store.Option
) - > error
Stores an object in the cache using a namespaced key. This method delegates to the underlying cache's Set method after applying the namespace.
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The context for the operation, allowing for cancellation and deadlines. |
| key | any | The key under which to store the object in the cache. |
| object | T | The object of type T to be stored in the cache. |
| options | store.Option | Optional settings for the cache operation, such as expiration. |
Returns
| Type | Description |
|---|---|
error | An error if the operation failed, otherwise nil. |
Delete()
@classmethod
def Delete(
ctx: context.Context,
key: any
) - > error
Removes an object from the cache using a namespaced key. This method delegates to the underlying cache's Delete method after applying the namespace.
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The context for the operation, allowing for cancellation and deadlines. |
| key | any | The key associated with the object to delete from the cache. |
Returns
| Type | Description |
|---|---|
error | An error if the operation failed, otherwise nil. |
GetType()
@classmethod
def GetType() - > string
Retrieves the type identifier of the underlying cache. This method delegates to the underlying cache's GetType method.
Returns
| Type | Description |
|---|---|
string | A string representing the type of the underlying cache. |