Skip to main content

idempotency

Attribute Macro idempotency 

Source
#[idempotency]
Expand description

实现幂等性属性的过程宏

§属性参数说明

  • name: 可选字符串字面量,指定 IdempotencyStore 的单例名称, 可以指定名称使用自己实现的 Store, 默认为memoryIdempotencyStore
  • key: 可选字符串字面量,用于获取请求头的键值,默认值为 Idempotency-key
  • cache_key_prefix: 可选字符串字面量,应用再缓存键的前缀
  • ttl: 可选整数字面量,缓存存活时间(Time To Live), 默认为秒

§注意

当前宏 只支持 Mehod 为 POST 你应该使用 PostMapping 或者 RequestMapping(method = "POST")

§示例

#[Idempotency(name = "myIdempotencyStore", key = "Idempotency-key", cache_key_prefix = "test", ttl = 6)]
#[PostMapping(path = "/createOrder")]
async fn create_order(order: String) -> impl IntoResponse {

    "Ok"
}

Process macros for implementing idempotent properties

§Description of Attribute Parameters

  • name: optional string literal, specifying the singleton name of IdempotencyStore, can specify the name to use their own implemented Store, default is memoryIdempotencyStore '
  • key: optional string literal, used to obtain the key value of the request header, default value is ` Idempotency key ``
  • cache_key_prefix: optional string literal, apply the prefix of the cached key again
  • ttl: optional integer face count, cache live time (Time To Live), default is seconds

§Attention

The current macro only supports Mehod as’ POST ’ You should use PostMapping or RequestMapping (method="POST")

§Example

#[idempotency(name = "myIdempotencyStore", key = "Idempotency-key", cache_key_prefix = "test", ttl = 6)]
#[PostMapping(path = "/createOrder")]
async fn create_order(order: String) -> impl IntoResponse {

    "Ok"
}