Interface CaptchaStore
- All Known Implementing Classes:
HashedCaptchaStore, MemoryCaptchaStore, RedisCaptchaStore
public interface CaptchaStore
Captcha Store - Interface for CAPTCHA storage
验证码存储 - 验证码存储接口
This interface defines the contract for storing and retrieving CAPTCHA data.
此接口定义了存储和检索验证码数据的契约。
Features | 主要功能:
- Store and retrieve CAPTCHA answers with TTL - 存储和检索带 TTL 的验证码答案
- Atomic get-and-remove for one-time validation - 原子获取并删除用于一次性验证
- Expiration management - 过期管理
- Factory methods for memory-based stores - 基于内存存储的工厂方法
Usage Examples | 使用示例:
CaptchaStore store = CaptchaStore.memory();
store.store("captcha-id", "answer", Duration.ofMinutes(5));
Optional<String> answer = store.getAndRemove("captcha-id");
Security | 安全性:
- Thread-safe: Implementation-dependent - 线程安全: 取决于实现
- Null-safe: No (parameters must be non-null) - 空值安全: 否(参数不能为空)
- Since:
- JDK 25, opencode-base-captcha V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclearAll()Clears all CAPTCHAs.voidClears all expired CAPTCHAs.booleanChecks if a CAPTCHA exists.Retrieves a CAPTCHA answer.getAndRemove(String id) Retrieves and removes a CAPTCHA answer.static HashedCaptchaStorehashed(CaptchaStore delegate) Wraps a store with answer hashing for defense in depth.static CaptchaStorememory()Creates a memory-based store.static CaptchaStorememory(int maxSize) Creates a memory-based store with max size.voidRemoves a CAPTCHA.intsize()Gets the current size.voidStores a CAPTCHA answer.
-
Method Details
-
store
-
get
-
getAndRemove
-
remove
-
exists
Checks if a CAPTCHA exists. 检查验证码是否存在。- Parameters:
id- the CAPTCHA ID | 验证码 ID- Returns:
- true if exists | 如果存在返回 true
-
clearExpired
void clearExpired()Clears all expired CAPTCHAs. 清除所有过期的验证码。 -
clearAll
void clearAll()Clears all CAPTCHAs. 清除所有验证码。 -
size
int size()Gets the current size. 获取当前大小。- Returns:
- the size | 大小
-
memory
-
memory
Creates a memory-based store with max size. 创建具有最大大小的基于内存的存储。- Parameters:
maxSize- the maximum size | 最大大小- Returns:
- the store | 存储
-
hashed
Wraps a store with answer hashing for defense in depth. 使用答案哈希包装存储以实现纵深防御。- Parameters:
delegate- the delegate store | 被包装的存储- Returns:
- the hashed store | 哈希存储
-