exists method

Future<bool> exists(
  1. String key, {
  2. Map<String, dynamic>? metadata,
})

Check if a key exists in the cache.

Respects TTL and other hook logic. Returns false if entry is expired.

Example:

if (await cache.exists('user:123')) {
  print('User is cached');
}

Implementation

Future<bool> exists(String key, {Map<String, dynamic>? metadata}) async {
  final ctx = PVCtx(
    cache: this,
    actionType: ActionType.exists,
    initialKey: key,
    initialMeta: metadata ?? {},
  );
  await ctx.queue(_orderedExistsHooks);
  return ctx.returnValue != null;
}