Expand description
Wordval cache proc macros: #[cached], #[cache_evict], #[cache_evict_pattern].
§#[cached(key = "...", ttl = 300, prefix = "...", unless = "...", empty_ttl = 60)]
Wraps an async handler with cache-aside pattern. The function must return ResResult<T>.
key is a template with {param} placeholders matching function parameter names.
ⓘ
#[cached(key = "product:{id}", ttl = 600)]
async fn get_product(id: u64) -> ResResult<Product> { ... }
#[cached(key = "products:{cat}", prefix = "store", unless = "__data.is_empty()")]
async fn get_products(cat: u64) -> ResResult<Vec<Product>> { ... }
#[cached(key = "user:{uid}", ttl = 3600, empty_ttl = 120)]
async fn get_user(uid: u64) -> ResResult<User> { ... }§#[cache_evict(key = "...", delay_ms = 500)]
Deletes a single cache entry on success, then deletes it again after
delay_ms milliseconds (delayed double-delete) to clear stale values
refilled by concurrent readers during the delete window.
delay_ms = 0 disables the second delete.
ⓘ
#[cache_evict(key = "product:{id}")] // default delay 500ms
async fn update_product(id: u64, data: UpdateReq) -> ResResult<()> { ... }
#[cache_evict(key = "user:{uid}", delay_ms = 800)]
async fn update_user(uid: u64, data: UpdateReq) -> ResResult<()> { ... }§#[cache_evict_pattern(pattern = "...", delay_ms = 500)]
Deletes all cache entries matching a glob pattern on success, with the
same delayed second delete as #[cache_evict].
ⓘ
#[cache_evict_pattern(pattern = "sys_dict:*")]
async fn refresh_all_dicts() -> ResResult<()> { ... }
#[cache_evict_pattern(pattern = "sys_dict:{dict_type}:*", delay_ms = 1000)]
async fn refresh_dict(dict_type: &str) -> ResResult<()> { ... }Attribute Macros§
- cache_
evict - cache_
evict_ pattern - Evict all cache entries matching a glob pattern after a successful write,
with a delayed second delete (delayed double-delete, default 500ms;
delay_ms = 0disables it). - cached