Skip to main content

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

NameTypeDescription
keyanyThe original key to be namespaced.

Returns

TypeDescription
stringThe 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

NameTypeDescription
ctxcontext.ContextThe context for the operation, allowing for cancellation and deadlines.
keyanyThe key associated with the object to retrieve from the cache.

Returns

TypeDescription
(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

NameTypeDescription
ctxcontext.ContextThe context for the operation, allowing for cancellation and deadlines.
keyanyThe key under which to store the object in the cache.
objectTThe object of type T to be stored in the cache.
optionsstore.OptionOptional settings for the cache operation, such as expiration.

Returns

TypeDescription
errorAn 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

NameTypeDescription
ctxcontext.ContextThe context for the operation, allowing for cancellation and deadlines.
keyanyThe key associated with the object to delete from the cache.

Returns

TypeDescription
errorAn 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

TypeDescription
stringA string representing the type of the underlying cache.