vit_cache 2.1.1 copy "vit_cache: ^2.1.1" to clipboard
vit_cache: ^2.1.1 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';

void main() async {
  // Create a cache with a fetch function
  var userInfoCache = SingularCache<Map<String, dynamic>>(
    ttl: Duration(seconds: 10),
    fetch: () async {
      // Simulate a network call to fetch user info
      await Future.delayed(Duration(seconds: 2));
      return {'name': 'Dave', 'auth_token': 'xxxxx'};
    },
  );

  // 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
160
points
28
downloads

Documentation

API reference

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

MIT (license)

More

Packages that depend on vit_cache