๐Ÿš€ Quick Cache Flutter

Breaking Changes

The method QuickCacheFlutter.instance.init is deprecated.
Use QuickCacheFlutter.init instead.

Features

Manage your cache securely with a single line of code, without sacrificing performance.

โšก Fast - uses Hive underneath for peak performance.

๐Ÿ”’ Secure - Encrypts everything you save.

โฒ๏ธ Expiry Duration - You can provide a stale period for each key.

๐Ÿ˜‰ Easy to use - Single line read write.

๐Ÿงน Active and passive cleaning - Automatically removes expired cache entries in the background while allowing manual cleanup when needed.

โณ Global Expiry Duration - Set a default expiration time for all cache entries, ensuring automatic cleanup without needing to specify expiry for each key.

Getting started

You have to initialize QuickCacheFlutter before runApp(Widget) (Call it after WidgetsFlutterBinding.ensureInitialized()):

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  QuickCacheFlutter.init(
      globalCacheSettingParams: GlobalCacheSettingParams(
          activeCleaning: true,
          globalExpiryDuration: const Duration(minutes: 5),
          maxCacheSize: 5000)); // maxCacheSize is in bytes.
  runApp(const MyApp());
}

GlobalCacheSettingParams

This version introduces GlobalCacheSettingParams, which aims to provide an easy way to manage settings while initializing cache.

๐Ÿงผ activeCleaning - When set to true, expired cache entries are automatically cleaned up in the background to free up space and maintain performance.

โณ globalExpiryDuration - Defines a default expiration time for all cache entries. If no expiry is specified for an individual key, this duration will be used instead. if globalExpiryDuration is not specified and expiryDuration is also not specified then key will remain in memory until it is manually deleted or cleaned if maxCacheSize exceeds.

๐Ÿ“ฆ maxCacheSize - Sets the maximum allowable cache size (in bytes). Once this limit is reached, older cache entries will be removed to make space for new ones by using LFU policy.

Usage

๐Ÿ“– QuickCacheFlutter.instance.readCache - Reads the value for given key

โœ๏ธ QuickCacheFlutter.instance.setCache - Save a single key value in database.

๐Ÿงน QuickCacheFlutter.instance.removeAllCache - Clear all cache from database.

๐Ÿ—‘๏ธ QuickCacheFlutter.instance.deleteValue -Deletes a single value.

If expiryDuration is not provided or set to null then the value will persist for app lifetime or till it is manually deleted.

QuickCacheFlutter.instance.setCache(
                    key: 'key',
                    value: value,
                    expiryDuration: const Duration(seconds: 20));

Additional information

Feedbacks, issues, contributions and suggestions are more than welcomed! ๐Ÿ˜

Connect with me

๐Ÿ‘‰ LinkedIn

๐Ÿ‘‰ X (twitter)