storeStructuredData method

Future<void> storeStructuredData(
  1. String id,
  2. String source,
  3. dynamic data
)

Stores structured data in the cache

id is the unique identifier for the data source is the source of the data (e.g., the URL) data is the data to store

Implementation

Future<void> storeStructuredData(
  String id,
  String source,
  dynamic data,
) async {
  final timestamp = DateTime.now().millisecondsSinceEpoch;

  // Store the data
  await _cache.put(_structuredDataKeyPrefix + id, {
    'id': id,
    'source': source,
    'timestamp': timestamp,
    'data': data,
  });

  // Update the list of IDs
  final ids = _cache.get(_structuredDataIdsKey) as List<dynamic>? ?? [];
  if (!ids.contains(id)) {
    ids.add(id);
    await _cache.put(_structuredDataIdsKey, ids);
  }

  // Update the list of sources
  final sources =
      _cache.get(_structuredDataSourcesKey) as List<dynamic>? ?? [];
  if (!sources.contains(source)) {
    sources.add(source);
    await _cache.put(_structuredDataSourcesKey, sources);
  }
}