vit_cache 1.1.0 copy "vit_cache: ^1.1.0" to clipboard
vit_cache: ^1.1.0 copied to clipboard

A Dart package for caching single values and multiple key-value pairs with a time-to-live (TTL) mechanism.

example/vit_cache_example.dart

import 'package:vit_cache/vit_cache.dart';

class UserInfoCache extends SingularCache<Map<String, dynamic>> {
  @override
  Future<Map<String, dynamic>> fetch() async {
    // Simulate a network call to fetch user info
    await Future.delayed(Duration(seconds: 2));
    return {'name': 'Dave', 'auth_token': 'xxxxx'};
  }

  @override
  Duration get ttl => Duration(seconds: 10);
}

void main() async {
  var userInfoCache = UserInfoCache();

  // Fetch and cache user info
  var info = await userInfoCache.get();
  print('User Info: $info');

  // Cache hit
  info = await userInfoCache.get();
  print('User Info: $info');

  // Update the cached value manually
  userInfoCache.update({'name': 'Dave', 'auth_token': 'xxxxx'});

  // Clear the cache
  userInfoCache.clear();
}
1
likes
0
points
32
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart package for caching single values and multiple key-value pairs with a time-to-live (TTL) mechanism.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on vit_cache