set<T> method
Stores a JSON-encodable value with optional ttl or expiresIn duration.
Example:
await storage.set('cart', {'items': [1, 2, 3]}, ttl: const Duration(days: 7));
Implementation
Future<void> set<T>(String key, T value, {Duration? ttl, Duration? expiresIn}) async {
final effectiveTtl = ttl ?? expiresIn;
final now = DateTime.now();
final wrapper = {
'data': value,
'savedAt': now.toIso8601String(),
'expiresAt': effectiveTtl != null ? now.add(effectiveTtl).toIso8601String() : null,
};
final serialized = jsonEncode(wrapper);
await adapter.write(key, serialized);
}