nosql_cache_manager 0.0.1 copy "nosql_cache_manager: ^0.0.1" to clipboard
nosql_cache_manager: ^0.0.1 copied to clipboard

A flutter cache manager for storing and retrieving data with Sembast.

Cache Manager for Flutter #

The cache_manager package provides an efficient solution for storing and retrieving data from a local cache in Flutter applications. This package leverages the Sembast database for persistent storage and uses the path_provider package to locate appropriate storage paths on the device. It is a perfect fit for developers who want to optimize network requests, reduce latency, and enhance user experience by caching data locally.

Features #

  • Efficient Data Caching: Cache data for faster access and reduced network requests.
  • Customizable Cache Expiry: Set custom expiration times for cached data.
  • Retrieve and Update Cached Data: Easily fetch and update data from the cache.
  • Clear Specific or Entire Cache: Remove individual cache entries or clear all cached data.
  • Persistent Storage: Uses Sembast for long-term data persistence.
  • Integration with Path Provider: Automatically locates the correct directories for storing cache data on Android and iOS devices.
  • Error Handling: Robust error handling when fetching, updating, or deleting cache entries.

Getting Started #

To use the cache_manager package in your Flutter project, add the following dependency to your pubspec.yaml file:

dependencies:
  cache_manager: ^1.0.0
copied to clipboard

Ensure that you also include the required packages:

dependencies:
  sembast: ^3.1.0
  path_provider: ^2.0.10

copied to clipboard

Usage #

Initialize Cache Manager Before you can store or retrieve data, initialize the CacheManager:

import 'package:cache_manager/cache_manager.dart';

void main() {
  CacheManager cacheManager = CacheManager();
}
copied to clipboard

Set Cache Data You can cache any data (e.g., API responses, user preferences, etc.) using the setCache method:

await cacheManager.setCache('user_profile',{'name': 'John Doe', 'email': 'john@example.com'}, duration: Duration(hours: 1), // Cache expiration time
);
copied to clipboard

Retrieve Cached Data Retrieve cached data with the getCache method. If the data has expired, it will return null:

final userProfile = await cacheManager.getCache('user_profile');

if (userProfile != null) {
  print('Cached User Profile: $userProfile');
} else {
  print('Cache expired or not available.');
}
copied to clipboard

Delete Cached Data You can delete specific cached data by key:

await cacheManager.deleteCache('user_profile');
copied to clipboard

Clear All Cached Data To remove all cache entries, use the clearAllCache method:

await cacheManager.clearAllCache();
copied to clipboard

Additional information #

Contributing #

We openly welcome contributions from the developer community. Whether it's improving the code, fixing bugs, or enhancing documentation, your input is valuable. To contribute, please follow these steps:

  1. Fork the repository on GitHub.
  2. Create a new branch for your changes.
  3. Make your changes in the branch.
  4. Submit a pull request with a clear description of the improvements.

Before contributing, please read our Contributing Guidelines for more details on the process and coding standards.

Filing Issues #

Encountering an issue or have a suggestion? We encourage you to file issues through our GitHub Issues Page. When filing an issue, please provide the following:

  • A clear and descriptive title.
  • A detailed description of the issue or suggestion.
  • Steps to reproduce the issue (if applicable).
  • Any relevant code snippets or error messages.

Support and Response #

Our team is committed to providing support for the package users. While we strive to respond to issues and pull requests promptly, please allow a reasonable amount of time for a response. For immediate support or specific queries, you can also reach out to us via official support channel.

1
likes
140
points
20
downloads

Publisher

verified publisherhorizondevelopers.cloud

Weekly Downloads

2024.10.04 - 2025.04.18

A flutter cache manager for storing and retrieving data with Sembast.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, path_provider, sembast

More

Packages that depend on nosql_cache_manager