simple_lru_cache 0.2.2 simple_lru_cache: ^0.2.2 copied to clipboard
A simple Least Recently Used (LRU) cache implementation in Dart.
Simple LRU Cache #
A simple and efficient Least Recently Used (LRU) cache implementation in Dart.
Features #
- Fixed-size cache with LRU eviction policy
- Generic key-value storage
- O(1) complexity for get, put, and remove operations
Usage #
import 'package:simple_lru_cache/simple_lru_cache.dart';
void main() {
final cache = LRUCache<int, String>(3);
cache.put(1, 'one');
cache.put(2, 'two');
cache.put(3, 'three');
print(cache.get(1)); // Outputs: one
cache.put(4, 'four'); // This will evict the least recently used item (2)
print(cache.containsKey(2)); // Outputs: false
}
Installation #
Add this to your package's pubspec.yaml
file:
dependencies:
simple_lru_cache: ^0.2.1
Then run dart pub get
.
License #
This project is licensed under the MIT License - see the LICENSE file for details.