Skip to main content

NewNamespacedCache

Creates a new namespaced cache that prefixes any key with the given namespace.

def NewNamespacedCache(
namespace: string,
underlying: cache.CacheInterface[T]
) - > NamespacedCache[T]

Creates a new namespaced cache that prefixes any key with the given namespace. This allows multiple logical caches to share the same underlying cache storage without key collisions.

Parameters​

NameTypeDescription
namespacestringThe string prefix to apply to all keys stored or retrieved from the underlying cache. This ensures keys within this namespaced cache are unique.
underlyingcache.CacheInterface[T]The actual cache implementation that will store the data. The namespaced cache will delegate all operations to this underlying cache after applying the namespace prefix.

Returns​

TypeDescription
NamespacedCache[T]A new NamespacedCache instance that wraps the underlying cache with the specified namespace.