cacherine 1.1.3 copy "cacherine: ^1.1.3" to clipboard
cacherine: ^1.1.3 copied to clipboard

A Dart library offering flexible in-memory cache implementations (FIFO, LRU, MRU, LFU) with both single-threaded and async options for concurrent environments.

cacherine #

Pub Version Dart CI OpenSSF Scorecard codecov Dart Documentation GitHub issues GitHub pull requests

cacherine is a simple and flexible memory cache library for Dart. It provides basic caching algorithms such as FIFO, LRU, MRU, and LFU. Both single-threaded and async-enabled versions are available to handle different usage scenarios.

If you want to choose the best cache algorithm for your app, you can use MonitoredCache in your development environment. It helps you monitor performance metrics (such as hit/miss rates, latency, and eviction alerts) so you can make data-driven decisions and optimize the algorithm you use.

Why cacherine? #

Dart/Flutter does not have a built-in caching solution similar to NSCache in Swift.
cacherine was created to provide a lightweight and flexible in-memory cache with common caching strategies like FIFO, LRU, MRU, and LFU.

Whether you need a simple single-threaded cache or an async-compatible solution for concurrent environments, cacherine offers an easy-to-use API.

Features #

  • FIFO (First In, First Out) — Learn more
  • EphemeralFIFO (FIFO-based cache where keys are removed after being accessed) — Learn more
  • LRU (Least Recently Used) — Learn more
  • MRU (Most Recently Used) — Learn more
  • LFU (Least Frequently Used) — Learn more
  • MonitoredCache (Includes performance monitoring with hit/miss rates, latency, and eviction alerts) — Learn more
  • Simple versions (e.g., SimpleFIFOCache) for single-threaded usage, and standard versions for multi-threaded environments

Installation #

Check the latest version on pub.dev and add it to your pubspec.yaml:

dependencies:
  cacherine: ^latest_version

Then, run the following command in your terminal:

dart pub get

Usage #

Basic Usage (Single-threaded) #

import 'package:cacherine/cacherine.dart';

void main() {
  final cache = SimpleFIFOCache<String, String>(maxSize: 5);
  cache.set('key1', 'value1');
  print(cache.get('key1')); // 'value1'
}

Async Usage (Async support) #

import 'package:cacherine/cacherine.dart';

void main() async {
  final cache = FIFOCache<String, String>(maxSize: 5);
  await cache.set('key1', 'value1');
  print(await cache.get('key1')); // 'value1'
}

Monitoring Usage #

If you want to monitor the performance of your cache and optimize the algorithm, use MonitoredCache. Learn more about MonitoredCache and performance monitoring.

API Reference #

Contributing #

Contributions are welcome! If you find a bug, have a feature request, or want to improve the code, feel free to open an issue or submit a pull request.

How to Contribute #

  1. Fork the repository and create a new branch.
  2. Make your changes and write tests if necessary.
  3. Ensure the code passes all checks (dart analyze, dart test).
  4. Open a pull request and describe your changes.

For major changes, please open an issue first to discuss your proposal.

We appreciate your support in making cacherine better! 🚀

Changelog #

All notable changes to this project will be documented in the CHANGELOG file.

See the full changelog here.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

1
likes
160
points
2.78k
downloads

Publisher

verified publisheryom-engine.com

Weekly Downloads

A Dart library offering flexible in-memory cache implementations (FIFO, LRU, MRU, LFU) with both single-threaded and async options for concurrent environments.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

synchronized

More

Packages that depend on cacherine