Function withCacheSchema

  • Creates a plugin that validates cache values against a standard schema.

    On add, put, and update operations the input value is validated against the provided schema before being stored. Optionally, get and getAndRemove outputs can also be validated on retrieval to ensure data integrity.

    Parameters

    • settings: WithCacheSchemaSettings

      Configuration for the schema validation.

      • schema: StandardSchemaV1

        A standard-schema-compliant schema used to validate cache values. Compatible with libraries such as Zod, ArkType, Valibot, and others that implement the StandardSchemaV1 specification.

      • OptionalshouldValidateOutput?: boolean

        Whether to validate values returned by get and getAndRemove on retrieval, in addition to validating values on write. When true, malformed data in the cache is caught at read time rather than silently returned.

        true
        

    Returns PluginFn<ICacheAdapter>

    A middleware plugin that wraps an ICacheAdapter.

    IMPORT_PATH: "@daiso-tech/core/cache/plugins"

    true