{
  "$schema" : "https://json-schema.org/draft/2020-12/schema",
  "$id" : "https://voltdb.com/voltsp/schemas/processor/voltdb-cache",
  "title" : "Voltdb-cache Processor Configuration",
  "description" : "The `voltdb-cache` processor that caches VoltDB server responses based on input parameters of a request.\nCaching can dramatically reduce network calls.\n\nNote the input object has to properly implement equals and hashCode contract defined by java.\nThe equals() and hashCode() methods must be overridden together to ensure that objects behave correctly in collections like HashMap and HashSet.\nThe contract states that if two objects are considered equal by the equals() method, they must return the same hash code, and the implementation should follow rules of reflexivity, symmetry, transitivity, consistency, and non-nullity.\nThe input object will be used as a key in underlying cache.\n\nA \"double miss\" occurs when a lookup request fails to find a value in both the cache and the underlying database.\nIn this scenario, the requested key is neither cached nor persisted and therefore cannot be resolved by the system.\nSuch requests are not processed further by the pipeline but may be routed to a dead-letter queue (DLQ) for handling.\n\nUser can relay on VoltSP standard configuration options to customise this processor.\n\nAs with the VoltDB flavored sinks this resource works with arrays of `Object`-s that correspond to stored procedure arguments.\nE.g. to invoke a stored procedure that has `public long run(long id, int anotherId, String someString)` method\nthe `Object[]` should contain `Long`, `Integer` and `String` or compatible types as defined in the VoltDB\n[documentation](https://docs.voltactivedata.com/UsingVoltDB/AppxDatatype.php).\n\nIn case of the system error this resource will retry procedure execution with exponential backoff.\nThe details of this behaviour are configurable using retry configuration.\n\nThe `voltdb-cache` operator requires VoltDBResource to be configured either in yaml or in java, see examples.\n",
  "type" : "object",
  "properties" : {
    "voltdb-cache" : {
      "type" : "object",
      "properties" : {
        "voltClientResource" : {
          "description" : "Client resource reference to be used when connecting to VoltDb cluster",
          "anyOf" : [ {
            "type" : "string"
          }, {
            "$ref" : "resource-voltdb-client.schema.json#/properties/voltdb-client"
          } ]
        },
        "procedureName" : {
          "type" : "string",
          "description" : "Called stored procedure name",
          "default" : "@AdHoc"
        },
        "sql" : {
          "type" : "string",
          "description" : "SQL query executed by @AdHoc procedure"
        },
        "paramsMapper" : {
          "type" : "string",
          "description" : "Given the input event this mapper returns parameters for named stored procedure or SQL query"
        },
        "keyMapper" : {
          "type" : "string",
          "description" : "A function that determines how the cache key is computed from the input.\nThe returned Object must properly implement equals() and hashCode() contract to ensure correct cache behavior.\nIf no custom key function is provided, the cache key will be generated automatically based on\nthe output of paramsMapper and, if applicable, the SQL query.\n"
        },
        "responseMapper" : {
          "type" : "string",
          "description" : "The function maps VoltDB response to an cacheable object. The object is cached for Object[] key returned from #paramsMapper.\nThis function must accept empty VoltTable result for scenarios when given params cannot be mapped to valid response,\n for such cases this method can return a fallback value and this value will be cached.\nThis function must return a value, but only non-null value will be cached.\n"
        },
        "computeFunction" : {
          "type" : "string",
          "description" : "The function computes result event for next operator in pipeline"
        },
        "maximumSize" : {
          "type" : "integer",
          "description" : "The maximum size of the cache",
          "default" : "100000",
          "minimum" : -2147483648,
          "maximum" : 2147483647
        },
        "expireAfterWrite" : {
          "type" : "string",
          "pattern" : "^(\\d+[smhd]|P(T|\\d+[YMD]).*)",
          "description" : "Each entry should be automatically removed from the cache once a this duration has elapsed\nafter the entry's creation, or the most recent replacement of its value.\n",
          "default" : "PT10M"
        },
        "retry" : {
          "type" : "object",
          "description" : "Configuration for retrying failed operations, including the number of retries and backoff delays.\n",
          "properties" : {
            "retries" : {
              "type" : "integer",
              "description" : "Number of retry attempts after a request failure.",
              "default" : "3",
              "minimum" : -2147483648,
              "maximum" : 2147483647
            },
            "backoffDelay" : {
              "type" : "string",
              "pattern" : "^(\\d+[smhd]|P(T|\\d+[YMD]).*)",
              "description" : "Initial delay before the first retry attempt.",
              "default" : "PT0.2S"
            },
            "maxBackoffDelay" : {
              "type" : "string",
              "pattern" : "^(\\d+[smhd]|P(T|\\d+[YMD]).*)",
              "description" : "Maximum delay between consecutive retry attempts.",
              "default" : "PT3S"
            }
          },
          "additionalProperties" : false
        },
        "exceptionHandler" : {
          "type" : "string",
          "description" : "A custom exception handler enabling interception of all errors related to this processor."
        }
      },
      "required" : [ "voltClientResource", "paramsMapper", "responseMapper", "computeFunction" ],
      "additionalProperties" : false
    }
  },
  "required" : [ "voltdb-cache" ],
  "additionalProperties" : false
}
